| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Class::Tiny::Chained; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3196
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
21
|
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
17
|
|
|
5
|
1
|
|
|
1
|
|
3
|
use Class::Tiny (); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
149
|
|
|
6
|
|
|
|
|
|
|
our @ISA = 'Class::Tiny'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.003'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub __gen_sub_body { |
|
11
|
3
|
|
|
3
|
|
417
|
my ($self, $name, $has_default, $default_type) = @_; |
|
12
|
|
|
|
|
|
|
|
|
13
|
3
|
50
|
33
|
|
|
10
|
if ($has_default && $default_type eq 'CODE') { |
|
|
|
50
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
0
|
return << "HERE"; |
|
15
|
|
|
|
|
|
|
sub $name { |
|
16
|
|
|
|
|
|
|
return ( |
|
17
|
|
|
|
|
|
|
( \@_ == 1 ) |
|
18
|
|
|
|
|
|
|
? ( exists \$_[0]{$name} ? \$_[0]{$name} : ( \$_[0]{$name} = \$default->( \$_[0] ) ) ) |
|
19
|
|
|
|
|
|
|
: do { \$_[0]{$name} = \$_[1]; \$_[0] } |
|
20
|
|
|
|
|
|
|
); |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
HERE |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
elsif ($has_default) { |
|
25
|
0
|
|
|
|
|
0
|
return << "HERE"; |
|
26
|
|
|
|
|
|
|
sub $name { |
|
27
|
|
|
|
|
|
|
return ( |
|
28
|
|
|
|
|
|
|
( \@_ == 1 ) |
|
29
|
|
|
|
|
|
|
? ( exists \$_[0]{$name} ? \$_[0]{$name} : ( \$_[0]{$name} = \$default ) ) |
|
30
|
|
|
|
|
|
|
: do { \$_[0]{$name} = \$_[1]; \$_[0] } |
|
31
|
|
|
|
|
|
|
); |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
HERE |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
else { |
|
36
|
3
|
|
|
|
|
9
|
return << "HERE"; |
|
37
|
|
|
|
|
|
|
sub $name { |
|
38
|
|
|
|
|
|
|
return \@_ == 1 ? \$_[0]{$name} : do { \$_[0]{$name} = \$_[1]; \$_[0] }; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
HERE |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 NAME |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Class::Tiny::Chained - Minimalist class construction, with chained attributes |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
In I: |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
package Person; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
use Class::Tiny::Chained qw( name ); |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
In I: |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
package Employee; |
|
63
|
|
|
|
|
|
|
use parent 'Person'; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
use Class::Tiny::Chained qw( ssn ), { |
|
66
|
|
|
|
|
|
|
timestamp => sub { time } # attribute with default |
|
67
|
|
|
|
|
|
|
}; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
In I: |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
use Employee; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $obj = Employee->new( name => "Larry", ssn => "111-22-3333" ); |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# attribute setters are chainable |
|
78
|
|
|
|
|
|
|
my $obj = Employee->new->name("Fred")->ssn("444-55-6666"); |
|
79
|
|
|
|
|
|
|
my $ts = $obj->name("Bob")->timestamp; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
L is a wrapper around L which makes the |
|
84
|
|
|
|
|
|
|
generated attribute accessors chainable; that is, when setting an attribute |
|
85
|
|
|
|
|
|
|
value, the object is returned so that further methods can be called. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 BUGS |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Report any issues on the public bugtracker. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 AUTHOR |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Dan Book |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
This software is Copyright (c) 2015 by Dan Book. |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This is free software, licensed under: |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
L, L |