line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Base::Lib; |
2
|
4
|
|
|
4
|
|
13847
|
use base 'Mojo::Base'; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
1673
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.003'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# Supported on Perl 5.22+ |
7
|
|
|
|
|
|
|
my $NAME |
8
|
|
|
|
|
|
|
= eval { require Sub::Util; Sub::Util->can('set_subname') } || sub { $_[1] }; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Declared here to avoid circular require problems in Mojo::Util |
11
|
|
|
|
|
|
|
sub _monkey_patch { |
12
|
2
|
|
|
2
|
|
3
|
my ($class, %patch) = @_; |
13
|
4
|
|
|
4
|
|
27149
|
no strict 'refs'; |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
83
|
|
14
|
4
|
|
|
4
|
|
12
|
no warnings 'redefine'; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
1361
|
|
15
|
2
|
|
|
|
|
18
|
*{"${class}::$_"} = $NAME->("${class}::$_", $patch{$_}) for keys %patch; |
|
2
|
|
|
|
|
9
|
|
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub import { |
19
|
7
|
|
|
7
|
|
12981
|
my $class = shift; |
20
|
|
|
|
|
|
|
#~ return unless my $flag = shift; |
21
|
|
|
|
|
|
|
|
22
|
7
|
|
|
|
|
6
|
my ($flag, $findbin,); |
23
|
7
|
|
|
|
|
11
|
my @flags = (); |
24
|
7
|
|
|
|
|
7
|
my @libs = (); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# parse flags |
27
|
7
|
|
66
|
|
|
28
|
while ((my $it = shift) || @_) { |
28
|
12
|
50
|
0
|
|
|
18
|
unshift @_, @$it |
29
|
|
|
|
|
|
|
and next |
30
|
|
|
|
|
|
|
if ref $it eq 'ARRAY'; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
next |
33
|
12
|
50
|
33
|
|
|
64
|
unless defined($it) && $it =~ m'/|\w';# / root lib? lets |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# controll flag |
36
|
12
|
100
|
|
|
|
45
|
if ($it =~ s'^(-\w+)'') { |
37
|
|
|
|
|
|
|
|
38
|
7
|
|
|
|
|
12
|
$flag = $1; |
39
|
7
|
100
|
50
|
|
|
33
|
push @flags, $flag |
40
|
|
|
|
|
|
|
and next |
41
|
|
|
|
|
|
|
unless $flag eq '-lib'; |
42
|
|
|
|
|
|
|
|
43
|
3
|
50
|
|
|
|
6
|
unshift @_, split m'[:;]+', $it # -lib:foo;bar |
44
|
|
|
|
|
|
|
if $it; |
45
|
|
|
|
|
|
|
|
46
|
3
|
|
|
|
|
8
|
next; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
} else { # non controll |
49
|
|
|
|
|
|
|
|
50
|
5
|
100
|
50
|
|
|
24
|
push @flags, $it |
|
|
|
66
|
|
|
|
|
51
|
|
|
|
|
|
|
and next |
52
|
|
|
|
|
|
|
unless $flag && $flag eq '-lib';# non lib items |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# abs lib |
57
|
4
|
100
|
50
|
|
|
12
|
push @libs, $it |
58
|
|
|
|
|
|
|
and next |
59
|
|
|
|
|
|
|
if $it =~ m'^/'; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# relative lib |
62
|
3
|
|
33
|
|
|
11
|
$findbin ||= do { |
63
|
3
|
|
|
|
|
929
|
require FindBin; |
64
|
3
|
|
|
|
|
1445
|
$FindBin::Bin; |
65
|
|
|
|
|
|
|
}; |
66
|
3
|
|
|
|
|
20
|
push @libs, $findbin.'/'.$it; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
7
|
100
|
66
|
|
|
19
|
if ( @libs && (my @ok_libs = grep{ my $lib = $_; not scalar grep($lib eq $_, @INC) } @libs) ) { |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
22
|
|
70
|
3
|
|
|
|
|
1180
|
require lib; |
71
|
3
|
|
|
|
|
1306
|
lib->import(@ok_libs); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$flag = shift @flags |
75
|
7
|
100
|
|
|
|
344
|
or return; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Base |
78
|
5
|
100
|
33
|
|
|
24
|
if ($flag eq '-base') { $flag = $class } |
|
1
|
100
|
|
|
|
2
|
|
|
|
50
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Strict |
81
|
3
|
|
|
|
|
3
|
elsif ($flag eq '-strict') { $flag = undef } |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Module |
84
|
|
|
|
|
|
|
elsif ((my $file = $flag) && !$flag->can('new')) { |
85
|
1
|
|
|
|
|
3
|
$file =~ s!::|'!/!g; |
86
|
1
|
|
|
|
|
246
|
require "$file.pm"; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# ISA |
90
|
5
|
100
|
|
|
|
14
|
if ($flag) { |
91
|
2
|
|
|
|
|
3
|
my $caller = caller; |
92
|
4
|
|
|
4
|
|
15
|
no strict 'refs'; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
101
|
|
93
|
|
|
|
|
|
|
# Useless use of a constant ("has") in void context Useless use of reference constructor in void context |
94
|
4
|
|
|
4
|
|
12
|
no warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
543
|
|
95
|
2
|
|
|
|
|
1
|
push @{"${caller}::ISA"}, $flag; |
|
2
|
|
|
|
|
16
|
|
96
|
2
|
|
|
0
|
|
8
|
_monkey_patch $caller, 'has', sub { attr($caller, @_) }; |
|
0
|
|
|
0
|
|
0
|
|
|
|
|
|
0
|
|
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Mojo modules are strict! |
100
|
5
|
|
|
|
|
59
|
$_->import for qw(strict warnings utf8); |
101
|
5
|
|
|
|
|
1295
|
feature->import(':5.10'); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=pod |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=encoding utf8 |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Доброго всем |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 Mojo::Base::Lib |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
¡ ¡ ¡ ALL GLORY TO GLORIA ! ! ! |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 VERSION |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
0.003 |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 NAME |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Mojo::Base::Lib - use Mojo::Base::Lib 'SomeBaseClass',-lib, qw(rel/path/lib /abs/path/lib); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SYNOPSIS |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Based on L where you found three forms usage. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
This module provide a fourth extended form for add extra lib directories to perl's search path. See |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
use Mojo::Base -lib, qw(rel/path/lib /abs/path/lib); |
132
|
|
|
|
|
|
|
use Mojo::Base -lib, ['lib1', 'lib2']; |
133
|
|
|
|
|
|
|
use Mojo::Base '-lib:lib1:lib2;lib3'; |
134
|
|
|
|
|
|
|
use Mojo::Base -strict, qw(-lib lib1 lib2); |
135
|
|
|
|
|
|
|
use Mojo::Base qw(-base -lib lib1 lib2); |
136
|
|
|
|
|
|
|
use Mojo::Base 'SomeBaseClass', qw(-lib lib1 lib2); |
137
|
|
|
|
|
|
|
use Mojo::Base qw(-lib lib1 lib2), 'SomeBaseClass'; # same above, different order allow |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
For relative lib path will use L module and C<$FindBin::Bin> is prepends to that lib. |
140
|
|
|
|
|
|
|
Libs always applied first even its last on flags list. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
All three L forms works also. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 SEE ALSO |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
L |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 AUTHOR |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Михаил Че (Mikhail Che), C<< >> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 BUGS / CONTRIBUTING |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Please report any bugs or feature requests at L. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 COPYRIGHT |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Copyright 2016 Mikhail Che. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
161
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |