line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Mojo::Bass; |
3
|
|
|
|
|
|
|
$Mojo::Bass::VERSION = '0.2.0'; |
4
|
|
|
|
|
|
|
# ABSTRACT: Mojo::Base + lexical "has" |
5
|
4
|
|
|
4
|
|
1621
|
use 5.018; |
|
4
|
|
|
|
|
35
|
|
6
|
4
|
|
|
4
|
|
1289
|
use Mojo::Base -strict; |
|
4
|
|
|
|
|
53718
|
|
|
4
|
|
|
|
|
30
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
BEGIN { |
9
|
4
|
|
|
4
|
|
936
|
our @ISA = qw(Mojo::Base); |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
1205
|
use Sub::Inject 0.2.0 (); |
|
4
|
|
|
|
|
1621
|
|
|
4
|
|
|
|
|
1393
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub import { |
15
|
17
|
|
|
17
|
|
197479
|
my $class = shift; |
16
|
17
|
100
|
|
|
|
1695
|
return unless my @flags = @_; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Base |
19
|
13
|
100
|
66
|
|
|
108
|
if ($flags[0] eq '-base') { $flags[0] = $class } |
|
4
|
100
|
|
|
|
14
|
|
|
|
100
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Strict |
22
|
5
|
|
|
|
|
12
|
elsif ($flags[0] eq '-strict') { $flags[0] = undef } |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Module |
25
|
|
|
|
|
|
|
elsif ((my $file = $flags[0]) && !$flags[0]->can('new')) { |
26
|
1
|
|
|
|
|
15
|
$file =~ s!::|'!/!g; |
27
|
1
|
|
|
|
|
217
|
require "$file.pm"; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Mojo modules are strict! |
31
|
13
|
|
|
|
|
267
|
$_->import for qw(strict warnings utf8); |
32
|
13
|
|
|
|
|
558
|
feature->import(':5.10'); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Signatures (Perl 5.20+) |
35
|
13
|
100
|
100
|
|
|
89
|
if (($flags[1] || '') eq '-signatures') { |
36
|
1
|
50
|
|
|
|
7
|
Carp::croak 'Subroutine signatures require Perl 5.20+' if $] < 5.020; |
37
|
1
|
|
|
|
|
21
|
feature->import('signatures'); |
38
|
1
|
|
|
|
|
20
|
warnings->unimport('experimental::signatures'); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# ISA |
42
|
13
|
100
|
|
|
|
1983
|
if ($flags[0]) { |
43
|
8
|
|
|
|
|
21
|
my $caller = caller; |
44
|
4
|
|
|
4
|
|
39
|
no strict 'refs'; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
990
|
|
45
|
8
|
|
|
|
|
14
|
push @{"${caller}::ISA"}, $flags[0]; |
|
8
|
|
|
|
|
88
|
|
46
|
8
|
|
|
8
|
|
51
|
@_ = ($caller, has => sub { Mojo::Base::attr($caller, @_) }); |
|
8
|
|
|
|
|
431
|
|
47
|
8
|
|
|
|
|
16
|
goto &{$class->can('_export_into')}; |
|
8
|
|
|
|
|
83
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _export_into { |
52
|
8
|
|
|
8
|
|
17
|
shift; |
53
|
8
|
|
|
|
|
33
|
goto &Sub::Inject::sub_inject; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#pod =encoding utf8 |
59
|
|
|
|
|
|
|
#pod |
60
|
|
|
|
|
|
|
#pod =head1 SYNOPSIS |
61
|
|
|
|
|
|
|
#pod |
62
|
|
|
|
|
|
|
#pod package Cat { |
63
|
|
|
|
|
|
|
#pod use Mojo::Bass -base; |
64
|
|
|
|
|
|
|
#pod |
65
|
|
|
|
|
|
|
#pod has name => 'Nyan'; |
66
|
|
|
|
|
|
|
#pod has ['age', 'weight'] => 4; |
67
|
|
|
|
|
|
|
#pod } |
68
|
|
|
|
|
|
|
#pod |
69
|
|
|
|
|
|
|
#pod package Tiger { |
70
|
|
|
|
|
|
|
#pod use Mojo::Bass 'Cat'; |
71
|
|
|
|
|
|
|
#pod |
72
|
|
|
|
|
|
|
#pod has friend => sub { Cat->new }; |
73
|
|
|
|
|
|
|
#pod has stripes => 42; |
74
|
|
|
|
|
|
|
#pod } |
75
|
|
|
|
|
|
|
#pod |
76
|
|
|
|
|
|
|
#pod package main; |
77
|
|
|
|
|
|
|
#pod use Mojo::Bass -strict; |
78
|
|
|
|
|
|
|
#pod |
79
|
|
|
|
|
|
|
#pod my $mew = Cat->new(name => 'Longcat'); |
80
|
|
|
|
|
|
|
#pod say $mew->age; |
81
|
|
|
|
|
|
|
#pod say $mew->age(3)->weight(5)->age; |
82
|
|
|
|
|
|
|
#pod |
83
|
|
|
|
|
|
|
#pod my $rawr = Tiger->new(stripes => 38, weight => 250); |
84
|
|
|
|
|
|
|
#pod say $rawr->tap(sub { $_->friend->name('Tacgnol') })->weight; |
85
|
|
|
|
|
|
|
#pod |
86
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
87
|
|
|
|
|
|
|
#pod |
88
|
|
|
|
|
|
|
#pod L works like L but C is imported |
89
|
|
|
|
|
|
|
#pod as lexical subroutine. |
90
|
|
|
|
|
|
|
#pod |
91
|
|
|
|
|
|
|
#pod =head1 CAVEATS |
92
|
|
|
|
|
|
|
#pod |
93
|
|
|
|
|
|
|
#pod =over 4 |
94
|
|
|
|
|
|
|
#pod |
95
|
|
|
|
|
|
|
#pod =item * |
96
|
|
|
|
|
|
|
#pod |
97
|
|
|
|
|
|
|
#pod L requires perl 5.18 or newer |
98
|
|
|
|
|
|
|
#pod |
99
|
|
|
|
|
|
|
#pod =item * |
100
|
|
|
|
|
|
|
#pod |
101
|
|
|
|
|
|
|
#pod Because a lexical sub does not behave like a package import, |
102
|
|
|
|
|
|
|
#pod some code may need to be enclosed in blocks to avoid warnings like |
103
|
|
|
|
|
|
|
#pod |
104
|
|
|
|
|
|
|
#pod "state" subroutine &has masks earlier declaration in same scope at... |
105
|
|
|
|
|
|
|
#pod |
106
|
|
|
|
|
|
|
#pod =back |
107
|
|
|
|
|
|
|
#pod |
108
|
|
|
|
|
|
|
#pod =head1 SEE ALSO |
109
|
|
|
|
|
|
|
#pod |
110
|
|
|
|
|
|
|
#pod L. |
111
|
|
|
|
|
|
|
#pod |
112
|
|
|
|
|
|
|
#pod =cut |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
__END__ |