| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 3 |  |  | 3 |  | 668 | use 5.008; | 
|  | 3 |  |  |  |  | 17 |  | 
| 2 | 3 |  |  | 3 |  | 15 | use strict; | 
|  | 3 |  |  |  |  | 19 |  | 
|  | 3 |  |  |  |  | 100 |  | 
| 3 | 3 |  |  | 3 |  | 17 | use warnings; | 
|  | 3 |  |  |  |  | 8 |  | 
|  | 3 |  |  |  |  | 197 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | package Sub::HandlesVia::HandlerLibrary::Scalar; | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | our $AUTHORITY = 'cpan:TOBYINK'; | 
| 8 |  |  |  |  |  |  | our $VERSION   = '0.050000'; | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 3 |  |  | 3 |  | 798 | use Sub::HandlesVia::HandlerLibrary; | 
|  | 3 |  |  |  |  | 8 |  | 
|  | 3 |  |  |  |  | 151 |  | 
| 11 |  |  |  |  |  |  | our @ISA = 'Sub::HandlesVia::HandlerLibrary'; | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 3 |  |  | 3 |  | 23 | use Sub::HandlesVia::Handler qw( handler ); | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 24 |  | 
| 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 |  | 79 | 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 | 46 | 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 |  | 73 | 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 | 47 | 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 |  | 63 | my ( $class, $attr, $method ) = @_; | 
| 60 | 1 |  |  |  |  | 7 | 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 | 32 | allow_getter_shortcuts => 0, | 
| 68 |  |  |  |  |  |  | } | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | 1; |