blib/lib/MooseX/Lists.pm

filter: Statementstmt 84.9% 62 / 73 Branchbran 69.0% 29 / 42 Conditioncond 42.8% 9 / 21 MC/DCmcdc 18.1% 2 / 11 Subroutinesub 84.6% 11 / 13 Podpod 42.8% 3 / 7 totaltotal 69.4% 116 / 167 CC 38 SCAR 21.7
CC
38
Cov
74%
:around
15.0
ArrayRef
15.0
has_list
10.3
CRAP 8.7
↑ Summary
1 # $Id: Lists.pm,v 1.12 2010/01/17 09:31:08 dk Exp $
2 package MooseX::Lists;
3  
4 5 our $VERSION = '0.05';
5 5 our $AUTHORITY = 'cpan:KARASIK';
6  
7 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Moose ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub ArrayRef
14 0 ▶{
Subroutine ArrayRef: not called CC=7 SCAR=27.1
Subroutine :around: called CC=7 SCAR=27.1
Pod documented
15 0 my $next = shift;
16 0 my $self = shift;
17 0 ▶ if ( 1 == @_ and $_[0] and ref($_[0]) eq 'ARRAY') {
Branch: 4 branches
BranchTrueFalseTotal
if (1 == @_ and $_[0] and ref $_[0] eq 'ARRAY') { } 0 0 0
elsif (@_) { } 0 0 0
if (1 == @_ and $_[0] and ref $_[0] eq 'ARRAY') { } 2 19 21
elsif (@_) { } 2 17 19
Condition33%4/12
1 == @_ and $_[0] and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
000
1 == @_ and $_[0]
!ll&&!rl&&r
000
1 == @_ and $_[0] and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
1902
1 == @_ and $_[0]
!ll&&!rl&&r
1902
MC/DC0%0/3
1 == @_ and $_[0] and ref $_[0] eq "ARRAY"
1 == @_ $_[0] ref $_[0] eq "ARRAY"
MC/DC33%1/3
1 == @_ and $_[0] and ref $_[0] eq "ARRAY"
1 == @_ $_[0] ref $_[0] eq "ARRAY"
Truth table0%0/4
A and B and C
A= 1 == @_B= $_[0]C= ref $_[0] eq "ARRAY"
ABCresult
0XX0
10X0
1100
1111
Truth table50%2/4
A and B and C
A= 1 == @_B= $_[0]C= ref $_[0] eq "ARRAY"
ABCresult
0XX0
10X0
1100
1111
18 0 return $self->$next(@_);
19 } elsif ( @_ ) {
20 0 return $self->$next(\@_);
21 } else {
22 0 my $r = $self-> $next;
23 0 ▶ return wantarray ? ( $r ? @$r : ()) : $r;
Branch: 4 branches
BranchTrueFalseTotal
wantarray ? : 0 0 0
$r ? : 0 0 0
wantarray ? : 11 6 17
$r ? : 10 1 11
24 }
25 }
26  
27 sub array_writer
28 0 ▶{
Subroutine array_writer: not called CC=1 SCAR=6.9
Pod undocumented
29 0 my $next = shift;
30 0 my $self = shift;
31 0 return $self->$next(\@_);
32 }
33  
34 sub HashRef
35 18 ▶{
Subroutine HashRef: called CC=8 SCAR=20.9
Pod documented
36 18 my $next = shift;
37 18 my $self = shift;
38 18 ▶ if ( 1 == @_ and $_[0] and ref($_[0]) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (1 == @_ and $_[0] and ref $_[0] eq 'HASH') { } 2 16 18
elsif (@_) { } 2 14 16
Condition66%4/6
1 == @_ and $_[0] and ref $_[0] eq "HASH"
!ll&&!rl&&r
1602
1 == @_ and $_[0]
!ll&&!rl&&r
1602
MC/DC33%1/3
1 == @_ and $_[0] and ref $_[0] eq "HASH"
1 == @_ $_[0] ref $_[0] eq "HASH"
Truth table50%2/4
A and B and C
A= 1 == @_B= $_[0]C= ref $_[0] eq "HASH"
ABCresult
0XX0
10X0
1100
1111
39 2 return $self->$next(@_);
40 } elsif ( @_ ) {
41 2 ▶ confess "Odd numbers ef elements in anonymous hash" if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 2 2
42 2 return $self->$next({@_});
43 } else {
44 14 my $r = $self-> $next;
45 14 ▶ return wantarray ? ( $r ? %$r : ()) : $r;
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 9 5 14
$r ? : 8 1 9
46 }
47 }
48  
49 sub hash_writer
50 3 ▶{
Subroutine hash_writer: called CC=2 SCAR=7.0
Pod undocumented
51 3 my $next = shift;
52 3 my $self = shift;
53 3 ▶ confess "Odd numbers ef elements in anonymous hash" if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 3 3
54 3 return $self->$next({@_});
55 }
56  
57 5 ▶sub anon_hash {{}}
Subroutine anon_hash: called CC=1 SCAR=0.0
Pod undocumented
58 9 ▶sub anon_array {[]}
Subroutine anon_array: called CC=1 SCAR=0.0
Pod undocumented
59  
60 sub has_list
61 10 ▶{
Subroutine has_list: called CC=10 SCAR=23.4
Pod documented
62 10 my ( $meta, $name, %options ) = @_;
63  
64 10 my ( $accessor,$writer,$default);
65 10 ▶ if ( defined $options{isa}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options{'isa'}) { } 8 2 10
66 8 ▶ if ( $options{isa} =~ /^ArrayRef/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($options{'isa'} =~ /^ArrayRef/) { } 4 4 8
elsif ($options{'isa'} =~ /^HashRef/) { } 4 0 4
67 4 $accessor = \&ArrayRef;
68 4 $writer = \&array_writer;
69 4 $default = \&anon_array;
70 } elsif ( $options{isa} =~ /^HashRef/) {
71 4 $accessor = \&HashRef;
72 4 $writer = \&hash_writer;
73 4 $default = \&anon_hash;
74 } else {
75 0 die "bad 'isa' option: must begin with either 'ArrayRef' or 'HashRef'";
76 }
77 } else {
78 2 $accessor = \&ArrayRef;
79 2 $writer = \&array_writer;
80 2 $default = \&anon_array;
81 }
82  
83 10 ▶ $options{default} = $default unless defined $options{default};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options{"default"} 10 0 10
84  
85 10 $meta-> add_attribute($name, %options);
86  
87 10 ▶ return if defined $options{is} and $options{is} eq 'bare';
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"is"} and $options{"is"} eq "bare" 0 10 10
Condition33%1/3
defined $options{"is"} and $options{"is"} eq "bare"
!ll&&!rl&&r
0100
MC/DC0%0/2
defined $options{"is"} and $options{"is"} eq "bare"
defined $options{"is"} $options{"is"} eq "bare"
Truth table33%1/3
A and B
A= defined $options{"is"}B= $options{"is"} eq "bare"
ABresult
0X0
100
111
88  
89 # hook the accessors
90 my @accessors =
91 10 grep { defined } map { $options{$_} } qw(reader accessor);
92 10 ▶ @accessors = $name unless @accessors;
Branch: 1 branch
BranchTrueFalseTotal
unless @accessors 6 4 10
93 10 $meta-> add_around_method_modifier( $_, $accessor) for @accessors;
94 $meta-> add_around_method_modifier( $options{writer}, $writer)
95 10 ▶ if $options{writer};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"writer"} 2 8 10
96 }
97  
98 5 Moose::Exporter-> setup_import_methods(
99 with_meta => [ 'has_list' ],
100 );
101  
102 5 1;
103  
104 __DATA__
↑ Summary