line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
916
|
use 5.008; |
|
3
|
|
|
|
|
13
|
|
2
|
3
|
|
|
3
|
|
25
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
86
|
|
3
|
3
|
|
|
3
|
|
21
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
232
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Sub::HandlesVia::HandlerLibrary::Scalar; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
8
|
|
|
|
|
|
|
our $VERSION = '0.046'; |
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
859
|
use Sub::HandlesVia::HandlerLibrary; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
158
|
|
11
|
|
|
|
|
|
|
our @ISA = 'Sub::HandlesVia::HandlerLibrary'; |
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
30
|
use Sub::HandlesVia::Handler qw( handler ); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
27
|
|
14
|
|
|
|
|
|
|
our @METHODS = qw( scalar_reference make_getter make_setter ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub scalar_reference { |
17
|
|
|
|
|
|
|
handler |
18
|
|
|
|
|
|
|
name => 'Scalar:scalar_reference', |
19
|
|
|
|
|
|
|
args => 0, |
20
|
|
|
|
|
|
|
template => '$GET;\\($SLOT)', |
21
|
|
|
|
|
|
|
documentation => "Returns a scalar reference to the attribute value's slot within its object.", |
22
|
|
|
|
|
|
|
_examples => sub { |
23
|
1
|
|
|
1
|
|
71
|
my ( $class, $attr, $method ) = @_; |
24
|
1
|
|
|
|
|
7
|
return CORE::join "", |
25
|
|
|
|
|
|
|
" my \$object = $class\->new( $attr => 10 );\n", |
26
|
|
|
|
|
|
|
" my \$ref = \$object->$method;\n", |
27
|
|
|
|
|
|
|
" \$\$ref++;\n", |
28
|
|
|
|
|
|
|
" say \$object->$attr; ## ==> 11\n", |
29
|
|
|
|
|
|
|
"\n"; |
30
|
|
|
|
|
|
|
}, |
31
|
3
|
|
|
3
|
1
|
61
|
allow_getter_shortcuts => 0, |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub make_getter { |
35
|
|
|
|
|
|
|
handler |
36
|
|
|
|
|
|
|
name => 'Scalar:make_getter', |
37
|
|
|
|
|
|
|
args => 0, |
38
|
|
|
|
|
|
|
template => 'my $s = $SELF; sub { unshift @_, $s; $GET }', |
39
|
|
|
|
|
|
|
documentation => "Returns a getter coderef.", |
40
|
|
|
|
|
|
|
_examples => sub { |
41
|
1
|
|
|
1
|
|
63
|
my ( $class, $attr, $method ) = @_; |
42
|
1
|
|
|
|
|
7
|
return CORE::join "", |
43
|
|
|
|
|
|
|
" my \$object = $class\->new( $attr => 10 );\n", |
44
|
|
|
|
|
|
|
" my \$getter = \$object->$method;\n", |
45
|
|
|
|
|
|
|
" \$object->_set_$attr( 11 );\n", |
46
|
|
|
|
|
|
|
" say \$getter->(); ## ==> 11\n", |
47
|
|
|
|
|
|
|
"\n"; |
48
|
|
|
|
|
|
|
}, |
49
|
3
|
|
|
3
|
1
|
56
|
allow_getter_shortcuts => 0, |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub make_setter { |
53
|
|
|
|
|
|
|
handler |
54
|
|
|
|
|
|
|
name => 'Scalar:make_setter', |
55
|
|
|
|
|
|
|
args => 0, |
56
|
|
|
|
|
|
|
template => 'my $s = $SELF; sub { my $val = shift; unshift @_, $s; « $val » }', |
57
|
|
|
|
|
|
|
documentation => "Returns a setter coderef.", |
58
|
|
|
|
|
|
|
_examples => sub { |
59
|
1
|
|
|
1
|
|
62
|
my ( $class, $attr, $method ) = @_; |
60
|
1
|
|
|
|
|
8
|
return CORE::join "", |
61
|
|
|
|
|
|
|
" my \$object = $class\->new( $attr => 10 );\n", |
62
|
|
|
|
|
|
|
" my \$setter = \$object->$method;\n", |
63
|
|
|
|
|
|
|
" \$setter->( 11 );\n", |
64
|
|
|
|
|
|
|
" say \$object->$attr; ## ==> 11\n", |
65
|
|
|
|
|
|
|
"\n"; |
66
|
|
|
|
|
|
|
}, |
67
|
3
|
|
|
3
|
1
|
30
|
allow_getter_shortcuts => 0, |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |