Graph/DataSet.pm

filter: Statementstmt 100% 56 / 56 Branchbran 100% 22 / 22 Conditioncond 77.7% 7 / 9 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 95.0% 95 / 100 CC 16 SCAR 23.6
CC
16
Cov
98%
BUILDARGS
15.0
_list_or_ref
2.0
BEGIN
1.0
CRAP 10.6
↑ Summary Graph.pm »
1 package Text::Graph::DataSet;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 our $VERSION = '0.83';
9  
10 8 has values => (
11 is => 'ro',
12 reader => 'get_values',
13 );
14 8 has labels => (
15 is => 'ro',
16 reader => 'get_labels',
17 );
18  
19 #
20 # This routine is quite complicated to support the bizarre interface that I
21 # originally supported.
22 sub BUILDARGS
23 49 ▶{
Subroutine BUILDARGS: called CC=15 SCAR=27.1
Pod undocumented
24 49 my ( $class, @args ) = @_;
25 49 ▶ return { values => [], labels => [] } if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 1 48 49
26 48 my ( $values, $labels, $hash ) = ( [], undef, undef );
27  
28 48 ▶ if( ref $args[0] eq ref [] )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $args[0] eq ref []) { } 42 6 48
elsif (ref $args[0] eq ref {}) { } 4 2 6
29 {
30 42 $values = shift @args;
31 42 ▶ if( ref $args[0] eq ref [] )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args[0] eq ref []) 36 6 42
32 {
33 36 $labels = shift @args;
34 }
35 }
36 elsif( ref $args[0] eq ref {} )
37 {
38 4 $hash = shift @args;
39 4 ▶ if( ref $args[0] eq ref [] )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args[0] eq ref []) 1 3 4
40 {
41 1 $labels = shift @args;
42 }
43 }
44 48 ▶ die "Odd number of parameters to new.\n" if @args % 2 == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 == 1 1 47 48
45 47 ▶ my %real_args = ( sort => sub { sort @_ }, @args );
Subroutine __ANON__: called CC=1 SCAR=0.0
46 47 my $sortref = delete $real_args{sort};
47 47 ▶ $hash ||= delete $real_args{hash};
Condition100%3/3
$hash ||= delete $real_args{"hash"}
l!l&&r!l&&!r
4142
MC/DC100%2/2
$hash ||= delete $real_args{"hash"}
$hash delete $real_args{"hash"}
Truth table100%3/3
A ||= B
A= $hashB= delete $real_args{"hash"}
ABresult
1X1
011
000
48 47 ▶ if( defined $hash )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash) 5 42 47
49 {
50 5 ▶ if( $sortref )
Branch: 1 branch
BranchTrueFalseTotal
if ($sortref) { } 4 1 5
51 {
52 4 my ( $pkg ) = caller;
53 4 ▶ $labels ||= [ $sortref->( keys %{$hash} ) ] if !$labels;
Branch: 1 branch
BranchTrueFalseTotal
unless $labels 3 1 4
Condition50%1/2
$labels ||= [&$sortref(keys %{$hash;})]
l!l
03
MC/DC0%0/1
$labels ||= [&$sortref(keys %{$hash;})]
$labels
Truth table50%1/2
A
A= $labels
Aresult
11
00
54 }
55 else
56 {
57 1 ▶ $labels ||= [ keys %{$hash} ];
Condition50%1/2
$labels ||= [keys %{$hash;}]
l!l
01
MC/DC0%0/1
$labels ||= [keys %{$hash;}]
$labels
Truth table50%1/2
A
A= $labels
Aresult
11
00
58 }
59 5 $values = [ @{$hash}{ @{$labels} } ];
60 5 $hash = undef;
61 }
62 47 ▶ $labels ||= [];
Condition100%2/2
$labels ||= []
l!l
416
MC/DC100%1/1
$labels ||= []
$labels
Truth table100%2/2
A
A= $labels
Aresult
11
00
63 47 ▶ push @{$labels}, ( '' ) x ( @{$values} - @{$labels} ) if @{$values} > @{$labels};
Branch: 1 branch
BranchTrueFalseTotal
if @{$values;} > @{$labels;} 7 40 47
64 47 return { values => $values, labels => $labels, %real_args };
65 }
66  
67 #
68 # Support the list or array ref original interface.
69 sub _list_or_ref
70 149 ▶{
Subroutine _list_or_ref: called CC=2 SCAR=6.9
71 149 my ( $orig, $self ) = @_;
72 149 my $val = $orig->( $self );
73 149 ▶ return wantarray ? @{$val} : $val;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 129 20 149
74 }
75  
76 8 around 'get_values' => \&_list_or_ref;
77 8 around 'get_labels' => \&_list_or_ref;
78  
79 8 1;
80 __END__
↑ Summary Graph.pm »