File Coverage

blib/lib/Sub/HandlesVia/HandlerLibrary/Code.pm
Criterion Covered Total %
statement 38 38 100.0
branch n/a
condition n/a
subroutine 21 21 100.0
pod 8 8 100.0
total 67 67 100.0


line stmt bran cond sub pod time code
1 10     10   726 use 5.008;
  10         39  
2 10     10   55 use strict;
  10         24  
  10         230  
3 10     10   49 use warnings;
  10         25  
  10         703  
4              
5              
6             our $AUTHORITY = 'cpan:TOBYINK';
7             our $VERSION = '0.045';
8              
9             use Sub::HandlesVia::HandlerLibrary;
10 10     10   3803 our @ISA = 'Sub::HandlesVia::HandlerLibrary';
  10         31  
  10         516  
11              
12             use Sub::HandlesVia::Handler qw( handler );
13 10     10   71 our @METHODS = qw(
  10         22  
  10         97  
14             execute execute_method
15             execute_list execute_method_list
16             execute_scalar execute_method_scalar
17             execute_void execute_method_void
18             );
19              
20             handler
21             name => 'Code:execute',
22             template => '$GET->(@ARG)',
23             usage => '@args',
24             prefer_shift_self => 1,
25             documentation => 'Calls the coderef, passing it any arguments.',
26             _examples => sub {
27             my ( $class, $attr, $method ) = @_;
28             return join "",
29 1     1   69 " my \$coderef = sub { 'code' };\n",
30 1         7 " my \$object = $class\->new( $attr => \$coderef );\n",
31             " \n",
32             " # Calls: \$coderef->( 1, 2, 3 )\n",
33             " \$object->$method\( 1, 2, 3 );\n",
34             "\n";
35             },
36             }
37              
38 40     40 1 275 handler
39             name => 'Code:execute_method',
40             template => '$GET->($SELF, @ARG)',
41             prefer_shift_self => 1,
42             usage => '@args',
43             documentation => 'Calls the coderef as if it were a method, passing any arguments.',
44             _examples => sub {
45             my ( $class, $attr, $method ) = @_;
46             return join "",
47             " my \$coderef = sub { 'code' };\n",
48 1     1   63 " my \$object = $class\->new( $attr => \$coderef );\n",
49 1         7 " \n",
50             " # Calls: \$coderef->( \$object, 1, 2, 3 )\n",
51             " \$object->$method\( 1, 2, 3 );\n",
52             "\n";
53             },
54             }
55              
56             handler
57 22     22 1 162 name => 'Code:execute_list',
58             template => 'my @shv_list = $GET->(@ARG); wantarray ? @shv_list : \@shv_list',
59             usage => '@args',
60             prefer_shift_self => 1,
61             documentation => 'Calls the coderef, passing it any arguments, and forcing list context. If called in scalar context, returns an arrayref.',
62             _examples => sub {
63             my ( $class, $attr, $method ) = @_;
64             return join "",
65             " my \$context;\n",
66             " my \$coderef = sub { \$context = wantarray(); 'code' };\n",
67 1     1   62 " my \$object = $class\->new( $attr => \$coderef );\n",
68 1         8 " \n",
69             " # Calls: \$coderef->( 1, 2, 3 )\n",
70             " my \$result = \$object->$method\( 1, 2, 3 );\n",
71             " \n",
72             " say Dumper( \$result ); ## ==> [ 'code' ]\n",
73             " say \$context; ## ==> true\n",
74             "\n";
75             },
76             }
77              
78             handler
79             name => 'Code:execute_method_list',
80 3     3 1 26 template => 'my @shv_list = $GET->($SELF, @ARG); wantarray ? @shv_list : \@shv_list',
81             prefer_shift_self => 1,
82             usage => '@args',
83             documentation => 'Calls the coderef as if it were a method, passing any arguments, and forcing list context. If called in scalar context, returns an arrayref.',
84             _examples => sub {
85             my ( $class, $attr, $method ) = @_;
86             return join "",
87             " my \$context;\n",
88             " my \$coderef = sub { \$context = wantarray(); 'code' };\n",
89             " my \$object = $class\->new( $attr => \$coderef );\n",
90 1     1   61 " \n",
91 1         7 " # Calls: \$coderef->( \$object, 1, 2, 3 )\n",
92             " my \$result = \$object->$method\( 1, 2, 3 );\n",
93             " \n",
94             " say Dumper( \$result ); ## ==> [ 'code' ]\n",
95             " say \$context; ## ==> true\n",
96             "\n";
97             },
98             }
99              
100             handler
101             name => 'Code:execute_scalar',
102             template => 'scalar( $GET->(@ARG) )',
103 3     3 1 26 usage => '@args',
104             prefer_shift_self => 1,
105             documentation => 'Calls the coderef, passing it any arguments, and forcing scalar context.',
106             _examples => sub {
107             my ( $class, $attr, $method ) = @_;
108             return join "",
109             " my \$context;\n",
110             " my \$coderef = sub { \$context = wantarray(); 'code' };\n",
111             " my \$object = $class\->new( $attr => \$coderef );\n",
112             " \n",
113 1     1   63 " # Calls: \$coderef->( 1, 2, 3 )\n",
114 1         7 " my \$result = \$object->$method\( 1, 2, 3 );\n",
115             " \n",
116             " say \$result; ## ==> 'code'\n",
117             " say \$context; ## ==> false\n",
118             "\n";
119             },
120             }
121              
122             handler
123             name => 'Code:execute_method_scalar',
124             template => 'scalar( $GET->($SELF, @ARG) )',
125             prefer_shift_self => 1,
126 3     3 1 27 usage => '@args',
127             documentation => 'Calls the coderef as if it were a method, passing any arguments, and forcing scalar context.',
128             _examples => sub {
129             my ( $class, $attr, $method ) = @_;
130             return join "",
131             " my \$context;\n",
132             " my \$coderef = sub { \$context = wantarray(); 'code' };\n",
133             " my \$object = $class\->new( $attr => \$coderef );\n",
134             " \n",
135             " # Calls: \$coderef->( \$object, 1, 2, 3 )\n",
136 1     1   62 " my \$result = \$object->$method\( 1, 2, 3 );\n",
137 1         7 " \n",
138             " say \$result; ## ==> 'code'\n",
139             " say \$context; ## ==> false\n",
140             "\n";
141             },
142             }
143              
144             handler
145             name => 'Code:execute_void',
146             template => '$GET->(@ARG); undef',
147             usage => '@args',
148             prefer_shift_self => 1,
149 3     3 1 24 documentation => 'Calls the coderef, passing it any arguments, and forcing void context. Returns undef.',
150             _examples => sub {
151             my ( $class, $attr, $method ) = @_;
152             return join "",
153             " my \$context;\n",
154             " my \$coderef = sub { \$context = wantarray(); 'code' };\n",
155             " my \$object = $class\->new( $attr => \$coderef );\n",
156             " \n",
157             " # Calls: \$coderef->( 1, 2, 3 )\n",
158             " my \$result = \$object->$method\( 1, 2, 3 );\n",
159 1     1   62 " \n",
160 1         7 " say \$result; ## ==> undef\n",
161             " say \$context; ## ==> undef\n",
162             "\n";
163             },
164             }
165              
166             handler
167             name => 'Code:execute_method_void',
168             template => '$GET->($SELF, @ARG); undef',
169             prefer_shift_self => 1,
170             usage => '@args',
171             documentation => 'Calls the coderef as if it were a method, passing any arguments, and forcing void context. Returns undef.',
172 3     3 1 28 _examples => sub {
173             my ( $class, $attr, $method ) = @_;
174             return join "",
175             " my \$context;\n",
176             " my \$coderef = sub { \$context = wantarray(); 'code' };\n",
177             " my \$object = $class\->new( $attr => \$coderef );\n",
178             " \n",
179             " # Calls: \$coderef->( \$object, 1, 2, 3 )\n",
180             " my \$result = \$object->$method\( 1, 2, 3 );\n",
181             " \n",
182 1     1   61 " say \$result; ## ==> undef\n",
183 1         6 " say \$context; ## ==> undef\n",
184             "\n";
185             },
186             }
187              
188             1;