Mojo/Base/Che.pm

filter: Statementstmt 72.5% 37 / 51 Branchbran 52.1% 24 / 46 Conditioncond 44.4% 4 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 55.5% 5 / 9 Podpod 100% 1 / 1 totaltotal 58.6% 71 / 121 CC 29 SCAR 30.5
CC
29
Cov
61%
attr
32.6
ioloop
30.0
new
12.0
CRAP 21.0
« Mojolicious/Che.pm ↑ Summary Mojolicious/Config.pm »
1 package Mojo::Base::Che;
2 # ABSTRACT: some patch for Mojo::Base(current 8.23)
3  
4 1 ▶use Mojo::Base -strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 #~ use mro;# weak
6  
7 # copy-paste sub Mojo::Base::attr + patch 1 line #~
8 199 ▶sub Mojo::Base::attr {
Subroutine attr: called CC=16 SCAR=34.9
Pod documented
9 199 my ($self, $attrs, $value, %kv) = @_;
10 199 ▶ return unless (my $class = ref $self || $self) && $attrs;
Branch: 1 branch
BranchTrueFalseTotal
unless my $class = ref $self || $self and $attrs 0 199 199
Condition33%2/6
my $class = ref $self || $self and $attrs
!ll&&!rl&&r
00199
ref $self || $self
l!l&&r!l&&!r
01990
MC/DC0%0/3
my $class = ref $self || $self and $attrs
ref $self $self $attrs
Truth table20%1/5
A || B and C
A= ref $selfB= $selfC= $attrs
ABCresult
00X0
1X00
0100
1X11
0111
11
12 199 ▶ Carp::croak 'Default has to be a code reference or constant value'
Branch: 1 branch
BranchTrueFalseTotal
if ref $value and ref $value ne "CODE" 0 199 199
Condition66%2/3
ref $value and ref $value ne "CODE"
!ll&&!rl&&r
841150
MC/DC0%0/2
ref $value and ref $value ne "CODE"
ref $value ref $value ne "CODE"
Truth table66%2/3
A and B
A= ref $valueB= ref $value ne "CODE"
ABresult
0X0
100
111
13 if ref $value && ref $value ne 'CODE';
14 199 ▶ Carp::croak 'Unsupported attribute option' if grep { $_ ne 'weak' } keys %kv;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ ne "weak";} keys %kv 0 199 199
15
16 # Weaken
17 199 ▶ if ($kv{weak}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kv{"weak"}) 9 190 199
18 9 state %weak_names;
19 9 ▶ unless ($weak_names{$class}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($weak_names{$class}) 9 0 9
20 9 my $names = $weak_names{$class} = [];
21 0 ▶ my $sub = sub {
Subroutine new: not called CC=3 SCAR=24.8
22 0 my $self = shift->next::method(@_);
23 0 ▶ ref $self->{$_} and Scalar::Util::weaken $self->{$_} for @$names;
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{$_} and builtin::weaken($self->{$_}) 0 0 0
24 0 return $self;
25 9 };
26 9 Mojo::Util::monkey_patch(my $base = $class . '::_Base', 'new', $sub);
27 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
28 9 unshift @{"${class}::ISA"}, $base;
29 }
30 9 ▶ push @{$weak_names{$class}}, ref $attrs eq 'ARRAY' ? @$attrs : $attrs;
Branch: 1 branch
BranchTrueFalseTotal
ref $attrs eq 'ARRAY' ? : 1 8 9
31 }
32
33 199 ▶ for my $attr (@{ref $attrs eq 'ARRAY' ? $attrs : [$attrs]}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $attrs eq 'ARRAY' ? : 31 168 199
34 #~ Carp::croak qq{Attribute "$attr" invalid} unless $attr =~ /^[a-zA-Z_]\w*$/;
35
36 # Very performance-sensitive code with lots of micro-optimizations
37 261 my $sub;
38 261 ▶ if ($kv{weak}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($kv{'weak'}) { } 10 251 261
elsif (ref $value) { } 118 133 251
elsif (defined $value) { } 58 75 133
39 10 ▶ if (ref $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) { } 7 3 10
40 0 ▶ $sub = sub {
Subroutine ioloop: not called CC=5 SCAR=34.0
41 return exists $_[0]{$attr}
42 ? $_[0]{$attr}
43 : (
44 ref($_[0]{$attr} = $value->($_[0]))
45 && Scalar::Util::weaken($_[0]{$attr}),
46 0 ▶ $_[0]{$attr}
Branch: 3 branches
BranchTrueFalseTotal
if @_ == 1 0 0 0
exists $_[0]{$attr} ? : 0 0 0
ref($_[0]{$attr} = &$value($_[0])) and builtin::weaken($_[0]{$attr}) 0 0 0
47 ) if @_ == 1;
48 0 ▶ ref($_[0]{$attr} = $_[1]) and Scalar::Util::weaken($_[0]{$attr});
Branch: 1 branch
BranchTrueFalseTotal
ref($_[0]{$attr} = $_[1]) and builtin::weaken($_[0]{$attr}) 0 0 0
49 0 $_[0];
50 7 };
51 }
52 else {
53 0 ▶ $sub = sub {
Subroutine parent: not called CC=3 SCAR=24.8
54 0 ▶ return $_[0]{$attr} if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
55 0 ▶ ref($_[0]{$attr} = $_[1]) and Scalar::Util::weaken($_[0]{$attr});
Branch: 1 branch
BranchTrueFalseTotal
ref($_[0]{$attr} = $_[1]) and builtin::weaken($_[0]{$attr}) 0 0 0
56 0 $_[0];
57 3 };
58 }
59 }
60 elsif (ref $value) {
61 23 ▶ $sub = sub {
Subroutine mapping: called CC=3 SCAR=11.0
62 return
63 23 ▶ exists $_[0]{$attr} ? $_[0]{$attr} : ($_[0]{$attr} = $value->($_[0]))
Branch: 2 branches
BranchTrueFalseTotal
if @_ == 1 22 1 23
exists $_[0]{$attr} ? : 17 5 22
64 if @_ == 1;
65 1 $_[0]{$attr} = $_[1];
66 1 $_[0];
67 118 };
68 }
69 elsif (defined $value) {
70 1 ▶ $sub = sub {
Subroutine wildcard_start: called CC=3 SCAR=15.4
71 1 ▶ return exists $_[0]{$attr} ? $_[0]{$attr} : ($_[0]{$attr} = $value)
Branch: 2 branches
BranchTrueFalseTotal
if @_ == 1 1 0 1
exists $_[0]{$attr} ? : 1 0 1
72 if @_ == 1;
73 0 $_[0]{$attr} = $_[1];
74 0 $_[0];
75 58 };
76 }
77 else {
78 $sub
79 0 ▶ = sub { return $_[0]{$attr} if @_ == 1; $_[0]{$attr} = $_[1]; $_[0] };
Subroutine asset: not called CC=2 SCAR=14.6
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
80 }
81 261 Mojo::Util::monkey_patch($class, $attr, $sub);
82 }
83 }
84  
85  
86  
87 #~ sub import {
88 #~ my ($class, $caller) = (shift, caller);
89 #~ my @flags = _lib_flags(@_);
90 #~ Mojo::Base->import(@flags); # patch 2
91 #~ }
92  
93  
94 #~ sub _lib_flags {# patch2
95 #~ my ($flag, $findbin, @flags, @libs) = ();
96  
97 #~ while ((my $it = shift) || @_) {# parse flags
98 #~ unshift @_, @$it
99 #~ and next
100 #~ if ref $it eq 'ARRAY';
101
102 #~ next
103 #~ unless defined($it) && $it =~ m'/|\w';# / root lib? lets
104  
105 #~ if ($it =~ s'^(-\w+)'') {# controll flag
106 #~ $flag = $1;
107 #~ push @flags, $flag
108 #~ and next
109 #~ unless $flag eq '-lib';
110  
111 #~ unshift @_, split m'[:;]+', $it # -lib:foo;bar
112 #~ if $it;
113  
114 #~ next;
115 #~ } elsif (!$flag || $flag ne '-lib') { # non controll
116 #~ push @flags, $it;
117 #~ next;
118 #~ # unless $flag && $flag eq '-lib';# non lib items
119 #~ }
120
121 #~ push @libs, $it # abs lib
122 #~ and next
123 #~ if $it =~ m'^/';
124
125 #~ $findbin ||= require FindBin && $FindBin::Bin;# relative lib
126 #~ push @libs, $findbin.'/'.$it;
127 #~ }
128
129 #~ my @ok_libs = grep { my $lib = $_; not scalar grep($lib eq $_, @INC) } @libs
130 #~ if @libs;
131 #~ require lib
132 #~ and lib->import(@ok_libs)
133 #~ if @ok_libs;
134
135 #~ return @flags;
136 #~ }
137  
138 1 1;
139  
140 =pod
141  
142 =encoding utf8
143  
144 Доброго всем
145  
146 =head1 Mojo::Base::Che
147  
148 ¡ ¡ ¡ ALL GLORY TO GLORIA ! ! !
149  
150 =head1 NAME
151  
152 Mojo::Base::Che - some patch for Mojo::Base
153  
154 =head1 DESCRIPTION
155  
156 Патчи L<Mojo::Base>.
157  
158 =head2 Причины патчей
159  
160 1. НЕТ!!NO!!!1111 Добавление путей в @INC;
161  
162 2. Разрешены хазы/атрибуты не только латиницей;
163  
164 =head1 SYNOPSIS
165  
166 НЕТ!!NO!!!1111 This module provide a extended form for add extra lib directories to perl's search path. See L<lib>
167  
168 НЕТ!!NO!!!1111 use Mojo::Base::Che -lib, qw(rel/path/lib /abs/path/lib);
169 НЕТ!!NO!!!1111 use Mojo::Base::Che -lib, ['lib1', 'lib2'];
170 НЕТ!!NO!!!1111 use Mojo::Base::Che '-lib:lib1:lib2;lib3';
171 НЕТ!!NO!!!1111 use Mojo::Base::Che -strict, qw(-lib lib1 lib2);
172 НЕТ!!NO!!!1111 use Mojo::Base::Che qw(-base -lib lib1 lib2);
173 НЕТ!!NO!!!1111 use Mojo::Base::Che 'SomeBaseClass', qw(-lib lib1 lib2);
174
175 use lib 'lib';
176 use Mojo::Base 'Foo';
177 use Mojo::Base::Che; # apply patch
178 # GLORY utf names allow
179 has [qw(☭хаза ☆маза)];
180  
181 НЕТ!!NO!!!1111 For relative lib path will use L<FindBin> module and C<$FindBin::Bin> is prepends to that lib.
182 НЕТ!!NO!!!1111 Libs always applied first even its last on flags list.
183  
184 =head1 SEE ALSO
185  
186 L<Mojo::Base>
187  
188 =head1 AUTHOR
189  
190 Михаил Че (Mikhail Che), C<< <mche[-at-]cpan.org> >>
191  
192 =head1 BUGS / CONTRIBUTING
193  
194 Please report any bugs or feature requests at L<https://github.com/mche/Mojolicious-Che/issues>.
195  
196 =head1 COPYRIGHT
197  
198 Copyright 2016-2018+ Mikhail Che.
199  
200 This library is free software; you can redistribute it and/or modify
201 it under the same terms as Perl itself.
202  
203 =cut
« Mojolicious/Che.pm ↑ Summary Mojolicious/Config.pm »