| 1 | package Class::Param::Compound; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use base 'Class::Param::Base'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use Params::Validate qw[]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 10 | 0 | ▶ | my $class = ref $_[0] ? ref shift : shift; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 11 | 0 | my $params = Params::Validate::validate_with( | |||||||||
| 12 | params => \@_, | ||||||||||
| 13 | spec => [ | ||||||||||
| 14 | ( | ||||||||||
| 15 | { | ||||||||||
| 16 | type => Params::Validate::OBJECT, | ||||||||||
| 17 | isa => 'Class::Param::Base', | ||||||||||
| 18 | optional => 0 | ||||||||||
| 19 | } | ||||||||||
| 20 | ) x @_ | ||||||||||
| 21 | ], | ||||||||||
| 22 | called => "$class\::new" | ||||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | 0 | return bless( $params, $class ); | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 0 | ▶ | sub params { | ||||||||
|
Subroutine
params: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 29 | 0 | ▶ | return wantarray ? @{ $_[0] } : [ @{ $_[0] } ]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | sub get { | ||||||||
|
Subroutine
get: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 33 | 0 | my ( $self, $name ) = @_; | |||||||||
| 34 | |||||||||||
| 35 | 0 | my @values = (); | |||||||||
| 36 | |||||||||||
| 37 | 0 | foreach my $param ( $self->params ) { | |||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | next unless $param->has($name); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | |||||||||||
| 41 | 0 | my $value = $param->get($name); | |||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | if ( ref $value eq 'ARRAY' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | push @values, @{ $value }; | |||||||||
| 45 | } | ||||||||||
| 46 | else { | ||||||||||
| 47 | 0 | push @values, $value; | |||||||||
| 48 | } | ||||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 0 | ▶ | return @values > 1 ? \@values : $values[0]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | sub set { | ||||||||
|
Subroutine
set: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 55 | 0 | my ( $self, $name, $value ) = @_; | |||||||||
| 56 | |||||||||||
| 57 | 0 | foreach my $param ( $self->params ) { | |||||||||
| 58 | 0 | $param->set( $name => $value ); | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 0 | return 1; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 0 | ▶ | sub clear { | ||||||||
|
Subroutine
clear: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 65 | 0 | my $self = shift; | |||||||||
| 66 | |||||||||||
| 67 | 0 | foreach my $param ( $self->params ) { | |||||||||
| 68 | 0 | $param->clear; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 0 | return 1; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 0 | ▶ | sub remove { | ||||||||
|
Subroutine
remove: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 75 | 0 | my ( $self, $name ) = @_; | |||||||||
| 76 | |||||||||||
| 77 | 0 | my @removed = (); | |||||||||
| 78 | |||||||||||
| 79 | 0 | foreach my $param ( $self->params ) { | |||||||||
| 80 | |||||||||||
| 81 | 0 | my $value = $param->remove($name); | |||||||||
| 82 | |||||||||||
| 83 | 0 | ▶ | if ( ref $value eq 'ARRAY' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 0 | push @removed, @{ $value }; | |||||||||
| 85 | } | ||||||||||
| 86 | else { | ||||||||||
| 87 | 0 | push @removed, $value; | |||||||||
| 88 | } | ||||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | 0 | ▶ | return @removed > 1 ? \@removed : $removed[0]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | 0 | ▶ | sub names { | ||||||||
|
Subroutine
names: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 95 | 0 | my $self = shift; | |||||||||
| 96 | |||||||||||
| 97 | 0 | my %seen = (); | |||||||||
| 98 | 0 | my @names = (); | |||||||||
| 99 | |||||||||||
| 100 | 0 | foreach my $param ( $self->params ) { | |||||||||
| 101 | 0 | push @names, $param->names; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 0 | return grep { $seen{$_}++ == 0 } @names; | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | 1 | 1; | |||||||||
| 108 | |||||||||||
| 109 | __END__ | ||||||||||