Construction/Role/AlternativeSources.pm

filter: Statementstmt 100% 48 / 48 Branchbran 77.2% 17 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 92.3% 72 / 78 CC 17 SCAR 15.3
CC
17
Cov
93%
alternatives
8.0
__ANON__
4.0
__ANON__
3.0
CRAP 4.6
« Construction/Circle.pm ↑ Summary Construction/Derivate/PointOnCircle.pm »
1 package Math::Geometry::Construction::Role::AlternativeSources;
2 16 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 16 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 16 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 C<Math::Geometry::Construction::Role::AlternativeSources> - one out of some
11  
12 =head1 VERSION
13  
14 Version 0.024
15  
16 =cut
17  
18 6 our $VERSION = '0.024';
19  
20 22 ▶sub alternatives {
Subroutine alternatives: called CC=8 SCAR=20.8
Pod undocumented
21 22 my ($class, %args) = @_;
22 22 my $meta = Class::MOP::Class->initialize($class);
23  
24 # complete spec (except triggers)
25 22 ▶ while(my ($alt_name, $alt_spec) = each %{$args{alternatives}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$args{"alternatives"};}) 70 22 92
26 $alt_spec->{is} = 'rw'
27 70 ▶ unless(exists($alt_spec->{is}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $alt_spec->{"is"} 70 0 70
28 $alt_spec->{reader} = '_'.$alt_name
29 70 ▶ unless(exists($alt_spec->{reader}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $alt_spec->{"reader"} 70 0 70
30 $alt_spec->{predicate} = '_has_'.$alt_name
31 70 ▶ unless(exists($alt_spec->{predicate}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $alt_spec->{"predicate"} 70 0 70
32 $alt_spec->{clearer} = '_clear_'.$alt_name
33 70 ▶ unless(exists($alt_spec->{clearer}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $alt_spec->{"clearer"} 70 0 70
34 }
35  
36 # create attributes with triggers
37 22 ▶ while(my ($alt_name, $alt_spec) = each %{$args{alternatives}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$args{"alternatives"};}) 70 22 92
38 352 ▶ my $_rules = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
39 352 my ($self) = @_;
40
41 352 foreach(keys %{$args{alternatives}}) {
42 1076 ▶ unless($_ eq $alt_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_ eq $alt_name) 724 352 1076
43 724 my $clearer = $args{alternatives}->{$_}->{clearer};
44 724 $self->$clearer;
45 }
46 }
47  
48 352 ▶ $self->clear_global_buffer if($args{clear_buffer});
Branch: 1 branch
BranchTrueFalseTotal
if $args{"clear_buffer"} 33 319 352
49 70 };
50 $alt_spec->{trigger} = $_rules
51 70 ▶ unless(exists($alt_spec->{trigger}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $alt_spec->{"trigger"} 70 0 70
52  
53 70 $meta->add_attribute($alt_name, %$alt_spec);
54 }
55  
56 79 ▶ my $_check = sub {
Subroutine _check_value_sources: called CC=3 SCAR=11.0
Subroutine __ANON__: called CC=3 SCAR=11.0
57 79 my ($self) = @_;
58 79 foreach(keys %{$args{alternatives}}) {
59 142 my $predicate = $args{alternatives}->{$_}->{predicate};
60 142 ▶ return if($self->$predicate);
Branch: 2 branches
BranchTrueFalseTotal
if $self->$predicate 77 65 142
if $self->$predicate 264 225 489
61 }
62 croak('At least one of the attributes '.
63 2 join(', ', keys %{$args{alternatives}}).
64 ' has to be specified when construction a '.
65 $class.' object');
66 22 };
67  
68 22 $meta->add_method('_check_'.$args{name} => $_check);
69 }
70  
71 6 1;
72  
73  
74 __END__
« Construction/Circle.pm ↑ Summary Construction/Derivate/PointOnCircle.pm »