EFA/Roles/Printable.pm

filter: Statementstmt 13.7% 4 / 29 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 1 / 2 Podpod 100% 1 / 1 totaltotal 13.6% 6 / 44 CC 10 SCAR 46.1
CC
10
Cov
10%
string
110.0
BEGIN
1.0
CRAP 100.1
« EFA.pm ↑ Summary EFA/RouteFactory.pm »
1 package WWW::EFA::Roles::Printable;
2 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 =head1 NAME
4  
5 WWW::EFA::Roles::Printable - makes objects printable
6  
7 =head1 SYNOPSIS
8
9 my $thing = WWW::EFA::SomeThing->new();
10 print $thing->string;
11  
12 package WWW::EFA::SomeThing;
13 use Moose;
14 with 'WWW::EFA::Roles::Printable'; # provides to_string
15  
16  
17 =head2 string
18  
19 This is a generic "to string" method, very similar to YAML::Dump, but a bit more tailored
20 to the architecture of this module.
21 e.g. Class::Date does not print out nicely with YAML::Dump, but does with this method.
22  
23 =cut
24 0 ▶sub string {
Subroutine string: not called CC=10 SCAR=47.0
Pod documented
25 0 my $self = shift;
26  
27 0 my $string = '';
28 0 foreach my $att( sort $self->meta->get_attribute_list ){
29 0 ▶ if( $self->$att ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->$att) 0 0 0
30 0 ▶ if( not ref( $self->$att ) ){
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $self->$att) { } 0 0 0
31 0 $string .= sprintf( "%-20s %s", $att, $self->$att );
32 } else {
33 0 $string .= sprintf( "%-20s %s\n", $att, ref( $self->$att ) );
34 0 my $sub_string = '';
35 0 ▶ if( ref( $self->$att ) eq 'ARRAY' ) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $self->$att eq 'ARRAY') { } 0 0 0
elsif (ref $self->$att eq 'HASH') { } 0 0 0
elsif ($self->$att->can('string')) { } 0 0 0
36 0 foreach( @{ $self->$att } ){
37 0 $sub_string .= $_->string;
38 0 $sub_string .= "\n";
39 }
40 } elsif( ref( $self->$att ) eq 'HASH' ) {
41 0 foreach( sort( keys( %{ $self->$att } ) ) ){
42 0 ▶ if( ref( $self->$att->{$_} ) ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->$att->{$_}) { } 0 0 0
43 0 $sub_string .= $self->$att->{$_}->string;
44 0 $sub_string .= "\n";
45 } else {
46 0 $sub_string .= sprintf( "%-20s %s\n", $_, $self->$att->{$_} );
47 }
48 }
49 }elsif( $self->$att->can( 'string' ) ){
50 0 $sub_string = $self->$att->string;
51 }else{
52 0 $sub_string = ">>> has no string method <<<<\n";
53 }
54 0 $sub_string =~ s/^/ /gm;
55 0 $string .= $sub_string;
56 }
57 0 $string .= "\n";
58 }
59 }
60 0 return $string;
61 }
62  
63  
64 2 1;
65  
66 =head1 METHODS
67  
68 =over 4
69  
70  
71 =back
72  
73 =head1 COPYRIGHT
74  
75 Copyright 2011, Robin Clarke, Munich, Germany
76  
77 =head1 AUTHOR
78  
79 Robin Clarke <perl@robinclarke.net>
80  
« EFA.pm ↑ Summary EFA/RouteFactory.pm »