lib/Reaction/Meta/InterfaceModel/Action/ParameterAttribute.pm

filter: Statementstmt 63.0% 29 / 46 Branchbran 32.1% 9 / 28 Conditioncond 44.4% 4 / 9 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 66.6% 6 / 9 Podpod 100% 4 / 4 totaltotal 52.4% 53 / 101 CC 18 SCAR 24.3
CC
18
Cov
51%
_check_single_valid
30.0
valid_value_collection
12.0
check_valid_value
11.0
CRAP 11.4
« lib/Reaction/UI/ViewPort/Collection/Role/Order.pm ↑ Summary lib/Reaction/UI/ViewPort/Field/.ToDo/TimeRange.pm »
1 package Reaction::Meta::InterfaceModel::Action::ParameterAttribute;
2  
3 5 ▶use Reaction::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use namespace::clean -except => [ qw(meta) ];
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 extends 'Reaction::Meta::Attribute';
8  
9  
10 5 has valid_values => (
11 isa => 'CodeRef',
12 is => 'rw',
13 predicate => 'has_valid_values'
14 );
15 114 ▶sub new {
Subroutine new: called CC=4 SCAR=14.8
Pod documented
16 114 my $self = shift->SUPER::new(@_); # work around immutable
17 114 ▶ if(!$self->has_valid_values and $self->has_type_constraint) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->has_valid_values and $self->has_type_constraint) 84 30 114
Condition66%2/3
not $self->has_valid_values and $self->has_type_constraint
!ll&&!rl&&r
30084
MC/DC50%1/2
not $self->has_valid_values and $self->has_type_constraint
not $self->has_valid_values $self->has_type_constraint
Truth table66%2/3
not(A) and B
A= not $self->has_valid_valuesB= $self->has_type_constraint
ABresult
0X0
100
111
18 84 my $tc = $self->type_constraint;
19 84 ▶ if($tc->isa('Moose::Meta::TypeConstraint::Enum')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tc->isa("Moose::Meta::TypeConstraint::Enum")) 0 84 84
20 0 ▶ $self->valid_values(sub { $tc->values });
Subroutine __ANON__: not called CC=1 SCAR=6.9
21 }
22 }
23 114 return $self;
24 }
25  
26 6 ▶sub check_valid_value {
Subroutine check_valid_value: called CC=7 SCAR=24.0
Pod documented
27 6 my ($self, $object, $value) = @_;
28 6 ▶ confess "Can't check_valid_value when no valid_values set"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_valid_values 0 6 6
29 unless $self->has_valid_values;
30 6 ▶ confess join " - ", blessed($object), $self->name
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->valid_values 0 6 6
31 unless ref $self->valid_values;
32 6 my $valid = $self->valid_values->($object, $self);
33 6 ▶ if ($self->type_constraint
Branch: 1 branch
BranchTrueFalseTotal
if ($self->type_constraint and $self->type_constraint->name eq 'ArrayRef' || $self->type_constraint->is_subtype_of('ArrayRef')) { } 6 0 6
Condition33%2/6
$self->type_constraint and $self->type_constraint->name eq "ArrayRef" || $self->type_constraint->is_subtype_of("ArrayRef")
!ll&&!rl&&r
006
$self->type_constraint->name eq "ArrayRef" or $self->type_constraint->is_subtype_of("ArrayRef")
l!l&&r!l&&!r
600
MC/DC0%0/3
$self->type_constraint and $self->type_constraint->name eq "ArrayRef" || $self->type_constraint->is_subtype_of("ArrayRef")
$self->type_constraint $self->type_constraint->name eq "ArrayRef" $self->type_constraint->is_subtype_of("ArrayRef")
Truth table25%1/4
A and B or C
A= $self->type_constraintB= $self->type_constraint->name eq "ArrayRef"C= $self->type_constraint->is_subtype_of("ArrayRef")
ABCresult
0XX0
1000
11X1
1011
34 && ($self->type_constraint->name eq 'ArrayRef'
35 || $self->type_constraint->is_subtype_of('ArrayRef'))) {
36 6 ▶ confess "Parameter type is array ref but passed value isn't"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "ARRAY" 0 6 6
37 unless ref($value) eq 'ARRAY';
38 0 return [ map { $self->_check_single_valid($valid => $_) } @$value ];
39 } else {
40 0 return $self->_check_single_valid($valid => $value);
41 }
42 };
43 0 ▶sub _check_single_valid {
Subroutine _check_single_valid: not called CC=5 SCAR=34.0
44 0 my ($self, $valid, $value) = @_;
45 0 ▶ return undef unless defined($value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
46 0 ▶ if (ref $valid eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $valid eq 'ARRAY') { } 0 0 0
47 0 ▶ return $value if grep { $_ eq $value } @$valid;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $value;} @$valid 0 0 0
48 } else {
49 0 ▶ $value = $value->ident_condition if blessed($value);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($value) 0 0 0
50 0 return $valid->find($value);
51 }
52 0 return undef; # XXX this is an assumption that undef is never valid
53 };
54 3 ▶sub all_valid_values {
Subroutine all_valid_values: called CC=3 SCAR=11.4
Pod documented
55 3 my ($self, $object) = @_;
56 3 ▶ confess "Can't call all_valid_values on an attribute without valid_values"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_valid_values 0 3 3
57 unless $self->has_valid_values;
58 3 my $valid = $self->valid_values->($object, $self);
59 3 ▶ return ((ref $valid eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
ref $valid eq 'ARRAY' ? : 0 3 3
60 ? @$valid
61 : $valid->all);
62 };
63 0 ▶sub valid_value_collection {
Subroutine valid_value_collection: not called CC=3 SCAR=24.8
Pod documented
64 0 my ($self, $object) = @_;
65 0 ▶ confess "Can't call valid_value_collection on an attribute without valid_values"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_valid_values 0 0 0
66 unless $self->has_valid_values;
67 0 my $valid = $self->valid_values->($object, $self);
68 0 ▶ confess "valid_values returned an arrayref, not a collection"
Branch: 1 branch
BranchTrueFalseTotal
if ref $valid eq "ARRAY" 0 0 0
69 if (ref $valid eq 'ARRAY');
70 0 return $valid;
71 };
72  
73 5 __PACKAGE__->meta->make_immutable(inline_constructor => 0);
74  
75  
76 5 1;
77  
78 =head1 NAME
79  
80 Reaction::Meta::InterfaceModel::Action::ParameterAttribute
81  
82 =head1 DESCRIPTION
83  
84 =head1 METHODS
85  
86 =head2 new
87  
88 =head2 valid_values
89  
90 =head2 has_valid_values
91  
92 =head2 check_valid_value
93  
94 =head2 all_valid_values
95  
96 =head2 valid_value_collection
97  
98 =head2 reader
99  
100 =head2 writer
101  
102 =head1 SEE ALSO
103  
104 L<Reaction::Meta::Attribute>
105  
106 =head1 AUTHORS
107  
108 See L<Reaction::Class> for authors.
109  
110 =head1 LICENSE
111  
112 See L<Reaction::Class> for the license.
113  
114 =cut
« lib/Reaction/UI/ViewPort/Collection/Role/Order.pm ↑ Summary lib/Reaction/UI/ViewPort/Field/.ToDo/TimeRange.pm »