Chart/GGPlot/Params.pm

filter: Statementstmt 88.9% 161 / 181 Branchbran 47.5% 38 / 80 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.4% 32 / 35 Podpod 90.0% 18 / 20 totaltotal 78.8% 249 / 316 CC 41 SCAR 13.6
CC
41
Cov
76%
values
12.0
delete
12.0
kv
12.0
CRAP 3.9
« Chart/GGPlot/Position.pm ↑ Summary Chart/GGPlot/Aes.pm »
1 package Chart::GGPlot::Params;
2  
3 # ABSTRACT: Collection of key-value pairs used in Chart::GGPlot
4  
5 18 ▶use Chart::GGPlot::Setup;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 18 ▶use Function::Parameters qw(classmethod);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 18 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 18 our $VERSION = '0.002003'; # VERSION
10  
11 18 ▶use List::AllUtils qw(pairgrep pairmap);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 18 ▶use Storable qw(dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 18 ▶use Type::Params;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 18 ▶use Types::Standard qw(HashRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 18 ▶use Chart::GGPlot::Types qw(GGParams);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 434 ▶classmethod new (@rest) {
Subroutine new: called CC=3 SCAR=11.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for classmethod new (expected 1, got ' . @_ . ')') 0 434 434
19 434 ▶ my %params = ( @rest == 1 ? %{ $rest[0] } : @rest );
Branch: 1 branch
BranchTrueFalseTotal
@rest == 1 ? : 6 428 434
20 my $self = bless {
21 729 ▶ _hash => %params->rename( sub { $class->transform_key( $_[0] ) } )
Subroutine __ANON__: called CC=1 SCAR=0.0
22 434 },
23 $class;
24  
25 434 $self->BUILD(\%params);
26 434 return $self;
27 18 }
28  
29 434 ▶sub BUILD { }
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
30  
31 1638 ▶sub _hash { $_[0]->{_hash} }
Subroutine _hash: called CC=1 SCAR=0.0
32  
33  
34 82 ▶classmethod transform_key ($key) { $key }
Subroutine transform_key: called CC=3 SCAR=11.2
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for classmethod transform_key (expected 2, got ' . @_ . ')') 0 82 82
@_ > 2 and Function::Parameters::_croak('Too many arguments for classmethod transform_key (expected 2, got ' . @_ . ')') 0 82 82
35  
36  
37 16 ▶method length () { scalar(@{$self->keys}); }
Subroutine length: called CC=3 SCAR=11.2
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for method length (expected 1, got ' . @_ . ')') 0 16 16
@_ > 1 and Function::Parameters::_croak('Too many arguments for method length (expected 1, got ' . @_ . ')') 0 16 16
38  
39  
40 144 ▶method exists ($key) { exists $self->_hash->{ $self->transform_key($key) }; }
Subroutine exists: called CC=3 SCAR=11.2
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method exists (expected 2, got ' . @_ . ')') 0 144 144
@_ > 2 and Function::Parameters::_croak('Too many arguments for method exists (expected 2, got ' . @_ . ')') 0 144 144
41  
42  
43 255 ▶method keys () { [ CORE::keys %{ $self->_hash } ]; }
Subroutine keys: called CC=3 SCAR=11.2
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for method keys (expected 1, got ' . @_ . ')') 0 255 255
@_ > 1 and Function::Parameters::_croak('Too many arguments for method keys (expected 1, got ' . @_ . ')') 0 255 255
44 50 ▶sub names { $_[0]->keys }
Subroutine names: called CC=1 SCAR=0.0
Pod documented
45  
46  
47 0 ▶method values () {
Subroutine values: not called CC=3 SCAR=24.8
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for method values (expected 1, got ' . @_ . ')') 0 0 0
@_ > 1 and Function::Parameters::_croak('Too many arguments for method values (expected 1, got ' . @_ . ')') 0 0 0
48 0 [ map { $self->at($_) } @{ $self->keys } ];
49 18 }
50  
51  
52 14 ▶method isempty () { $self->length == 0; }
Subroutine isempty: called CC=3 SCAR=11.2
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for method isempty (expected 1, got ' . @_ . ')') 0 14 14
@_ > 1 and Function::Parameters::_croak('Too many arguments for method isempty (expected 1, got ' . @_ . ')') 0 14 14
53  
54  
55 0 ▶method delete ($key) {
Subroutine delete: not called CC=3 SCAR=24.8
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method delete (expected 2, got ' . @_ . ')') 0 0 0
@_ > 2 and Function::Parameters::_croak('Too many arguments for method delete (expected 2, got ' . @_ . ')') 0 0 0
56 0 delete $self->_hash->{ $self->transform_key($key) };
57 18 }
58  
59  
60 361 ▶method set ( $key, $value ) {
Subroutine set: called CC=3 SCAR=11.2
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 3 and Function::Parameters::_croak('Too few arguments for method set (expected 3, got ' . @_ . ')') 0 361 361
@_ > 3 and Function::Parameters::_croak('Too many arguments for method set (expected 3, got ' . @_ . ')') 0 361 361
61 361 $self->_hash->{ $self->transform_key($key) } = $value;
62 18 }
63  
64  
65 858 ▶sub _at {
Subroutine _at: called CC=1 SCAR=0.0
66 858 my ( $self, $key ) = @_;
67 858 $self->_hash->{$key};
68 }
69  
70 696 ▶method at ($key) { $self->_at( $self->transform_key($key) ); }
Subroutine at: called CC=3 SCAR=11.2
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method at (expected 2, got ' . @_ . ')') 0 696 696
@_ > 2 and Function::Parameters::_croak('Too many arguments for method at (expected 2, got ' . @_ . ')') 0 696 696
71  
72  
73 111 ▶method flatten () {
Subroutine flatten: called CC=3 SCAR=11.2
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for method flatten (expected 1, got ' . @_ . ')') 0 111 111
@_ > 1 and Function::Parameters::_croak('Too many arguments for method flatten (expected 1, got ' . @_ . ')') 0 111 111
74 111 map { $_ => $self->_at($_) } @{ $self->keys };
75 18 }
76  
77  
78 29 ▶method hslice ($keys) {
Subroutine hslice: called CC=3 SCAR=11.1
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method hslice (expected 2, got ' . @_ . ')') 0 29 29
@_ > 2 and Function::Parameters::_croak('Too many arguments for method hslice (expected 2, got ' . @_ . ')') 0 29 29
79 29 my $class = ref($self);
80 29 return bless( { _hash => { map { $_ => $self->at($_) } @$keys } }, $class );
81 18 }
82 18 *slice = \&hslice;
83  
84  
85 0 ▶method kv () {
Subroutine kv: not called CC=3 SCAR=24.8
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for method kv (expected 1, got ' . @_ . ')') 0 0 0
@_ > 1 and Function::Parameters::_croak('Too many arguments for method kv (expected 1, got ' . @_ . ')') 0 0 0
86 0 return [ map { [ $_ => $self->_at($_) ] } @{ $self->keys } ];
87 18 }
88  
89  
90 31 ▶method merge ($other, $skip_undef=false) {
Subroutine merge: called CC=5 SCAR=16.1
Pod documented
Branch: 3 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method merge (expected 2, got ' . @_ . ')') 0 31 31
@_ > 3 and Function::Parameters::_croak('Too many arguments for method merge (expected 3, got ' . @_ . ')') 0 31 31
@_ < 2 and $skip_undef = &false() 13 18 31
91 ($other) = Type::Params::validate( [$other],
92 31 ▶ GGParams->plus_coercions( HashRef, sub { ref($self)->new($_) } ) );
Subroutine __ANON__: called CC=1 SCAR=0.0
93  
94 31 my @other_data = $other->flatten;
95 31 ▶ if ($skip_undef) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip_undef) 18 13 31
96 18 ▶ @other_data = pairgrep { defined $b } @other_data;
Subroutine __ANON__: called CC=1 SCAR=0.0
97 }
98 31 my $class = ref($self);
99 31 return bless( { _hash => { $self->flatten, @other_data } }, $class );
100 18 }
101  
102  
103 18 ▶method defaults ($other) {
Subroutine defaults: called CC=4 SCAR=14.3
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method defaults (expected 2, got ' . @_ . ')') 0 18 18
@_ > 2 and Function::Parameters::_croak('Too many arguments for method defaults (expected 2, got ' . @_ . ')') 0 18 18
104 18 ▶ return $self->clone unless defined $other;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $other 0 18 18
105 18 return $other->merge( $self, true );
106 18 }
107  
108  
109 9 ▶method rename ($href_or_coderef) {
Subroutine rename: called CC=4 SCAR=13.9
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method rename (expected 2, got ' . @_ . ')') 0 9 9
@_ > 2 and Function::Parameters::_croak('Too many arguments for method rename (expected 2, got ' . @_ . ')') 0 9 9
110 9 my $class = ref($self);
111  
112 9 my $new_hash;
113 9 ▶ if ( Ref::Util::is_coderef($href_or_coderef) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (Ref::Util::XS::is_coderef($href_or_coderef)) { } 8 1 9
114 8 ▶ my $f = sub { $href_or_coderef->( $self->transform_key( $_[0] ) ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
115 8 $new_hash = $self->_hash->rename($f);
116 }
117 else {
118 my $mapping = {
119 1 ▶ pairmap { $self->transform_key($a) => $self->transform_key($b) }
Subroutine __ANON__: called CC=1 SCAR=0.0
120 1 $href_or_coderef->flatten
121 };
122 1 $new_hash = $self->_hash->rename($mapping);
123 }
124 9 return bless( { _hash => $new_hash }, $class );
125 18 }
126  
127  
128 11 ▶method as_hashref () { $self->_hash; }
Subroutine as_hashref: called CC=3 SCAR=11.2
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for method as_hashref (expected 1, got ' . @_ . ')') 0 11 11
@_ > 1 and Function::Parameters::_croak('Too many arguments for method as_hashref (expected 1, got ' . @_ . ')') 0 11 11
129  
130  
131 11 ▶method copy () {
Subroutine copy: called CC=3 SCAR=11.3
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for method copy (expected 1, got ' . @_ . ')') 0 11 11
@_ > 1 and Function::Parameters::_croak('Too many arguments for method copy (expected 1, got ' . @_ . ')') 0 11 11
132 11 return dclone($self);
133 18 }
134  
135 18 *clone = \&copy;
136  
137 18 1;
138  
139 __END__
« Chart/GGPlot/Position.pm ↑ Summary Chart/GGPlot/Aes.pm »