| 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
| |||||||||||||||||||
| 19 | 434 | ▶ | my %params = ( @rest == 1 ? %{ $rest[0] } : @rest ); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 35 | |||||||||||||||||||
| 36 | |||||||||||||||||||
| 37 | 16 | ▶ | method length () { scalar(@{$self->keys}); } | ||||||||||||||||
|
Subroutine
length: called CC=3 SCAR=11.2
Pod
documented
Branch: 2 branches
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 41 | |||||||||||||||||||
| 42 | |||||||||||||||||||
| 43 | 255 | ▶ | method keys () { [ CORE::keys %{ $self->_hash } ]; } | ||||||||||||||||
|
Subroutine
keys: called CC=3 SCAR=11.2
Pod
documented
Branch: 2 branches
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 53 | |||||||||||||||||||
| 54 | |||||||||||||||||||
| 55 | 0 | ▶ | method delete ($key) { | ||||||||||||||||
|
Subroutine
delete: not called CC=3 SCAR=24.8
Pod
documented
Branch: 2 branches
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 71 | |||||||||||||||||||
| 72 | |||||||||||||||||||
| 73 | 111 | ▶ | method flatten () { | ||||||||||||||||
|
Subroutine
flatten: called CC=3 SCAR=11.2
Pod
documented
Branch: 2 branches
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 104 | 18 | ▶ | return $self->clone unless defined $other; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 129 | |||||||||||||||||||
| 130 | |||||||||||||||||||
| 131 | 11 | ▶ | method copy () { | ||||||||||||||||
|
Subroutine
copy: called CC=3 SCAR=11.3
Pod
documented
Branch: 2 branches
| |||||||||||||||||||
| 132 | 11 | return dclone($self); | |||||||||||||||||
| 133 | 18 | } | |||||||||||||||||
| 134 | |||||||||||||||||||
| 135 | 18 | *clone = \© | |||||||||||||||||
| 136 | |||||||||||||||||||
| 137 | 18 | 1; | |||||||||||||||||
| 138 | |||||||||||||||||||
| 139 | __END__ | ||||||||||||||||||