Venus/Role/Printable.pm

filter: Statementstmt 92.8% 26 / 28 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.6% 11 / 12 Podpod 75.0% 6 / 8 totaltotal 86.5% 45 / 52 CC 3 SCAR 3.2
CC
3
Cov
88%
print_string
2.1
say_string
2.1
printer
2.0
CRAP 1.4
« Venus/Number.pm ↑ Summary Venus/Role/Dumpable.pm »
1 package Venus::Role::Printable;
2  
3 61 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 61 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 61 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 61 ▶use Venus::Role 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 61 with 'Venus::Role::Dumpable';
11  
12 # METHODS
13  
14 sub print {
15 2 ▶ my ($self, @args) = @_;
Subroutine print: called CC=1 SCAR=0.0
Pod documented
16  
17 2 return $self->printer($self->dump(@args));
18 }
19  
20 sub print_pretty {
21 2 ▶ my ($self, @args) = @_;
Subroutine print_pretty: called CC=1 SCAR=0.0
Pod documented
22  
23 2 return $self->printer($self->dump_pretty(@args));
24 }
25  
26 sub print_string {
27 1 ▶ my ($self, $method, @args) = @_;
Subroutine print_string: called CC=2 SCAR=7.2
Pod documented
28  
29 1 ▶ return $self->printer($method ? scalar($self->$method(@args)) : $self);
Branch: 1 branch
BranchTrueFalseTotal
$method ? : 0 1 1
30 }
31  
32 sub printer {
33 0 ▶ my ($self, @args) = @_;
Subroutine printer: not called CC=1 SCAR=6.9
Pod undocumented
34  
35 0 return CORE::print(STDOUT @args);
36 }
37  
38 sub say {
39 2 ▶ my ($self, @args) = @_;
Subroutine say: called CC=1 SCAR=0.0
Pod documented
40  
41 2 return $self->printer($self->dump(@args), "\n");
42 }
43  
44 sub say_pretty {
45 2 ▶ my ($self, @args) = @_;
Subroutine say_pretty: called CC=1 SCAR=0.0
Pod documented
46  
47 2 return $self->printer($self->dump_pretty(@args), "\n");
48 }
49  
50 sub say_string {
51 1 ▶ my ($self, $method, @args) = @_;
Subroutine say_string: called CC=2 SCAR=7.2
Pod documented
52  
53 1 ▶ return $self->printer(($method ? scalar($self->$method(@args)) : $self), "\n");
Branch: 1 branch
BranchTrueFalseTotal
$method ? : 0 1 1
54 }
55  
56 # EXPORTS
57  
58 sub EXPORT {
59 [
60 62 ▶ 'dump',
Subroutine EXPORT: called CC=1 SCAR=0.0
Pod undocumented
61 'dump_pretty',
62 'print',
63 'print_pretty',
64 'print_string',
65 'printer',
66 'say',
67 'say_pretty',
68 'say_string',
69 ]
70 }
71  
72 61 1;
73  
74  
75  
76 =head1 NAME
77  
78 Venus::Role::Printable - Printable Role
79  
80 =cut
81  
82 =head1 ABSTRACT
83  
84 Printable Role for Perl 5
85  
86 =cut
87  
88 =head1 SYNOPSIS
89  
90 package Example;
91  
92 use Venus::Class;
93  
94 with 'Venus::Role::Printable';
95  
96 attr 'test';
97  
98 sub execute {
99 return [@_];
100 }
101  
102 sub printer {
103 return [@_];
104 }
105  
106 package main;
107  
108 my $example = Example->new(test => 123);
109  
110 # $example->say;
111  
112 =cut
113  
114 =head1 DESCRIPTION
115  
116 This package provides a mechanism for outputting (printing) objects or the
117 return value of a dispatched method call to STDOUT.
118  
119 =cut
120  
121 =head1 INTEGRATES
122  
123 This package integrates behaviors from:
124  
125 L<Venus::Role::Dumpable>
126  
127 =cut
128  
129 =head1 METHODS
130  
131 This package provides the following methods:
132  
133 =cut
134  
135 =head2 print
136  
137 print(Any @data) (Any)
138  
139 The print method prints a stringified representation of the underlying data.
140  
141 I<Since C<0.01>>
142  
143 =over 4
144  
145 =item print example 1
146  
147 package main;
148  
149 my $example = Example->new(test => 123);
150  
151 my $print = $example->print;
152  
153 # bless({test => 123}, 'Example')
154  
155 # 1
156  
157 =back
158  
159 =over 4
160  
161 =item print example 2
162  
163 package main;
164  
165 my $example = Example->new(test => 123);
166  
167 my $print = $example->print('execute', 1, 2, 3);
168  
169 # [bless({test => 123}, 'Example'),1,2,3]
170  
171 # 1
172  
173 =back
174  
175 =cut
176  
177 =head2 print_pretty
178  
179 print_pretty(Any @data) (Any)
180  
181 The print_pretty method prints a stringified human-readable representation of
182 the underlying data.
183  
184 I<Since C<0.01>>
185  
186 =over 4
187  
188 =item print_pretty example 1
189  
190 package main;
191  
192 my $example = Example->new(test => 123);
193  
194 my $print_pretty = $example->print_pretty;
195  
196 # bless({ test => 123 }, 'Example')
197  
198 # 1
199  
200 =back
201  
202 =over 4
203  
204 =item print_pretty example 2
205  
206 package main;
207  
208 my $example = Example->new(test => 123);
209  
210 my $print_pretty = $example->print_pretty('execute', 1, 2, 3);
211  
212 # [
213 # bless({ test => 123 }, 'Example'),
214 # 1,
215 # 2,
216 # 3
217 # ]
218  
219 # 1
220  
221 =back
222  
223 =cut
224  
225 =head2 print_string
226  
227 print_string(Str | CodeRef $method, Any @args) (Any)
228  
229 The print_string method prints a string representation of the underlying data
230 without using a dump. This method supports dispatching, i.e. providing a
231 method name and arguments whose return value will be acted on by this method.
232  
233 I<Since C<0.09>>
234  
235 =over 4
236  
237 =item print_string example 1
238  
239 package main;
240  
241 my $example = Example->new(test => 123);
242  
243 my $print_string = $example->print_string;
244  
245 # 'Example'
246  
247 # 1
248  
249 =back
250  
251 =cut
252  
253 =head2 say
254  
255 say(Any @data) (Any)
256  
257 The say method prints a stringified representation of the underlying data, with
258 a trailing newline.
259  
260 I<Since C<0.01>>
261  
262 =over 4
263  
264 =item say example 1
265  
266 package main;
267  
268 my $example = Example->new(test => 123);
269  
270 my $say = $example->say;
271  
272 # bless({test => 123}, 'Example')\n
273  
274 # 1
275  
276 =back
277  
278 =over 4
279  
280 =item say example 2
281  
282 package main;
283  
284 my $example = Example->new(test => 123);
285  
286 my $say = $example->say;
287  
288 # [bless({test => 123}, 'Example'),1,2,3]\n
289  
290 # 1
291  
292 =back
293  
294 =cut
295  
296 =head2 say_pretty
297  
298 say_pretty(Any @data) (Any)
299  
300 The say_pretty method prints a stringified human-readable representation of the
301 underlying data, with a trailing newline.
302  
303 I<Since C<0.01>>
304  
305 =over 4
306  
307 =item say_pretty example 1
308  
309 package main;
310  
311 my $example = Example->new(test => 123);
312  
313 my $say_pretty = $example->say_pretty;
314  
315 # bless({ test => 123 }, 'Example')\n
316  
317 # 1
318  
319 =back
320  
321 =over 4
322  
323 =item say_pretty example 2
324  
325 package main;
326  
327 my $example = Example->new(test => 123);
328  
329 my $say_pretty = $example->say_pretty;
330  
331 # [
332 # bless({ test => 123 }, 'Example'),
333 # 1,
334 # 2,
335 # 3
336 # ]\n
337  
338 # 1
339  
340 =back
341  
342 =cut
343  
344 =head2 say_string
345  
346 say_string(Str | CodeRef $method, Any @args) (Any)
347  
348 The say_string method prints a string representation of the underlying data
349 without using a dump, with a trailing newline. This method supports
350 dispatching, i.e. providing a method name and arguments whose return value will
351 be acted on by this method.
352  
353 I<Since C<0.09>>
354  
355 =over 4
356  
357 =item say_string example 1
358  
359 package main;
360  
361 my $example = Example->new(test => 123);
362  
363 my $say_string = $example->say_string;
364  
365 # "Example\n"
366  
367 # 1
368  
369 =back
370  
371 =cut
« Venus/Number.pm ↑ Summary Venus/Role/Dumpable.pm »