OFC/Types.pm

filter: Statementstmt 92.8% 104 / 112 Branchbran 71.4% 20 / 28 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 82.5% 33 / 40 Podpod 100% 1 / 1 totaltotal 84.2% 161 / 191 CC 15 SCAR 5.2
CC
15
Cov
87%
__ANON__
3.3
hex
3.0
__ANON__
3.0
CRAP 1.7
« OFC.pm ↑ Summary OFC/Role/OFCDataLines.pm »
1 package Chart::OFC::Types;
2 41 $Chart::OFC::Types::VERSION = '0.12';
3 41 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 41 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 41 ▶use Graphics::ColorNames;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 41 ▶use List::MoreUtils qw( any );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 41 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 subtype 'Chart::OFC::Type::Color'
11 => as 'Str',
12 239 ▶ => where { ( uc $_ ) =~ /^\#[0-9A-F]{6}$/ }
Subroutine __ANON__: called CC=1 SCAR=0.0
13 0 ▶ => message { "$_ is not a valid six-digit hex color" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
14  
15 41 coerce 'Chart::OFC::Type::Color'
16 => from 'Str'
17 => via \&_name_to_hex_color;
18  
19 {
20 41 my $names = Graphics::ColorNames->new();
21 sub _name_to_hex_color
22 56 ▶ {
Subroutine _name_to_hex_color: called CC=1 SCAR=0.0
23 41 ▶ no warnings 'uninitialized'; ## no critic ProhibitNoWarnings
Subroutine BEGIN: called CC=1 SCAR=0.0
24 56 return uc $names->hex( $_, '#' );
25 }
26 }
27  
28 41 subtype 'Chart::OFC::Type::NonEmptyArrayRef'
29 => as 'ArrayRef'
30 103 ▶ => where { return scalar @{ $_ } > 0 };
Subroutine __ANON__: called CC=1 SCAR=0.0
31  
32 {
33 41 my $constraint = find_type_constraint('Num');
34  
35 subtype 'Chart::OFC::Type::NonEmptyArrayRefOfNums'
36 => as 'Chart::OFC::Type::NonEmptyArrayRef',
37 24 ▶ => where { return 0 if any { ! $constraint->check($_) } @{ $_ };
Subroutine __ANON__: called CC=2 SCAR=6.9
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { not $constraint->check($_); } , @{$_;}) 1 23 24
38 23 return 1; }
39 2 ▶ => message { 'array reference must contain only numbers and cannot be empty' };
Subroutine __ANON__: called CC=1 SCAR=0.0
40  
41 subtype 'Chart::OFC::Type::NonEmptyArrayRefOfNumsOrUndefs'
42 => as 'Chart::OFC::Type::NonEmptyArrayRef',
43 35 ▶ => where { return 0 if any { defined && ! $constraint->check($_) } @{ $_ };
Subroutine __ANON__: called CC=2 SCAR=7.0
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 2 branches
BranchTrueFalseTotal
if &any(sub { defined $_ and not $constraint->check($_); } , @{$_;}) 0 35 35
defined $_ and not $constraint->check($_) 106 3 109
44 35 return 1; }
45 0 ▶ => message { 'array reference cannot be empty and must contain numbers or undef' };
Subroutine __ANON__: not called CC=1 SCAR=1.2
46 }
47  
48 {
49 41 my $constraint = find_type_constraint('Chart::OFC::Type::NonEmptyArrayRefOfNumsOrUndefs');
50  
51 subtype 'Chart::OFC::Type::NonEmptyArrayRefOfArrayRefsOfNumsOrUndefs'
52 => as 'Chart::OFC::Type::NonEmptyArrayRef',
53 13 ▶ => where { return 0 if any { defined && ! $constraint->check($_) } @{ $_ };
Subroutine __ANON__: called CC=2 SCAR=7.0
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 2 branches
BranchTrueFalseTotal
if &any(sub { defined $_ and not $constraint->check($_); } , @{$_;}) 1 12 13
defined $_ and not $constraint->check($_) 22 0 22
54 12 return 1; }
55 2 ▶ => message { 'array reference cannot be empty and must contain more array references of numbers or undef' };
Subroutine __ANON__: called CC=1 SCAR=0.0
56 }
57  
58 {
59 41 my $constraint = find_type_constraint('Chart::OFC::Type::Color');
60  
61 subtype 'Chart::OFC::Type::NonEmptyArrayRefOfColors'
62 => as 'Chart::OFC::Type::NonEmptyArrayRef',
63 6 ▶ => where { return 0 unless @{ $_ } > 0;
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
unless @{$_;} > 0 0 6 6
64 6 ▶ return 0 if any { ! $constraint->check($_) } @{ $_ };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { not $constraint->check($_); } , @{$_;}) 4 2 6
65 2 return 1; }
66 2 ▶ => message { 'array reference cannot be empty and must be a list of colors' };
Subroutine __ANON__: called CC=1 SCAR=0.0
67  
68 coerce 'Chart::OFC::Type::NonEmptyArrayRefOfColors'
69 => from 'ArrayRef'
70 4 ▶ => via { [ map { $constraint->coerce($_) } @{ $_ } ] };
Subroutine __ANON__: called CC=1 SCAR=0.0
71 }
72  
73 {
74 41 ▶ my $constraint = find_type_constraint('Chart::OFC::Dataset') || class_type('Chart::OFC::Dataset');
Condition66%2/3
find_type_constraint('Chart::OFC::Dataset') || class_type('Chart::OFC::Dataset')
l!l&&r!l&&!r
3380
MC/DC0%0/2
find_type_constraint('Chart::OFC::Dataset') || class_type('Chart::OFC::Dataset')
find_type_constraint('Chart::OFC::Dataset') class_type('Chart::OFC::Dataset')
Truth table66%2/3
A || B
A= find_type_constraint('Chart::OFC::Dataset')B= class_type('Chart::OFC::Dataset')
ABresult
1X1
011
000
75  
76 subtype 'Chart::OFC::Type::NonEmptyArrayRefOfTypedDatasets'
77 => as 'Chart::OFC::Type::NonEmptyArrayRef',
78 11 ▶ => where { return 0 unless @{ $_ } > 0;
Subroutine __ANON__: called CC=3 SCAR=11.8
Branch: 1 branch
BranchTrueFalseTotal
unless @{$_;} > 0 0 11 11
79 11 ▶ return 0 if any { ! ( $constraint->check($_) && $_->can('type') ) } @{ $_ };
Subroutine __ANON__: called CC=2 SCAR=7.9
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { not $constraint->check($_) && $_->can("type"); } , @{$_;}) 0 11 11
Condition33%1/3
$constraint->check($_) && $_->can('type')
!ll&&!rl&&r
0013
MC/DC0%0/2
$constraint->check($_) && $_->can('type')
$constraint->check($_) $_->can('type')
Truth table33%1/3
A && B
A= $constraint->check($_)B= $_->can('type')
ABresult
0X0
100
111
80 11 return 1; }
81 0 ▶ => message { 'array reference cannot be must be a list of typed datasets' };
Subroutine __ANON__: not called CC=1 SCAR=1.2
82 }
83  
84 41 ▶unless ( find_type_constraint('Chart::OFC::AxisLabel' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (find_type_constraint("Chart::OFC::AxisLabel")) 39 2 41
85 {
86 subtype 'Chart::OFC::AxisLabel'
87 => as 'Object'
88 16 ▶ => where { $_->isa('Chart::OFC::AxisLabel') };
Subroutine __ANON__: called CC=1 SCAR=0.0
89 }
90  
91 coerce 'Chart::OFC::AxisLabel'
92 => from 'HashRef'
93 1 ▶ => via { Chart::OFC::AxisLabel->new( %{ $_ } ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
94 => from 'Str'
95 9 ▶ => via { Chart::OFC::AxisLabel->new( label => $_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
96  
97 subtype 'Chart::OFC::Type::Angle'
98 => as 'Int'
99 4 ▶ => where { $_ >= 0 && $_ <= 359 }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_ >= 0 and $_ <= 359 4 0 4
100 0 ▶ => message { "$_ is not a number from 0-359" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
101  
102 subtype 'Chart::OFC::Type::Opacity'
103 => as 'Int'
104 35 ▶ => where { $_ >= 0 && $_ <= 100 }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_ >= 0 and $_ <= 100 35 0 35
105 0 ▶ => message { "$_ is not a number from 0-100" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
106  
107 subtype 'Chart::OFC::Type::PosInt'
108 => as 'Int'
109 118 ▶ => where { $_ > 0 }
Subroutine __ANON__: called CC=1 SCAR=0.0
110 0 ▶ => message { 'must be a positive integer' };
Subroutine __ANON__: not called CC=1 SCAR=1.2
111  
112 subtype 'Chart::OFC::Type::PosOrZeroInt'
113 => as 'Int'
114 3 ▶ => where { $_ >= 0 }
Subroutine __ANON__: called CC=1 SCAR=0.0
115 0 ▶ => message { 'must be an integer greater than or equal to zero' };
Subroutine __ANON__: not called CC=1 SCAR=1.2
116  
117 41 subtype 'Chart::OFC::Type::Size'
118 => as 'Chart::OFC::Type::PosInt';
119  
120 41 enum 'Chart::OFC::Type::Orientation' => [qw( horizontal vertical diagonal )];
121  
122  
123 {
124 # Monkey-patch to shut up an annoying warning!
125  
126 package ## no critic ProhibitMultiplePackages
127 Graphics::ColorNames;
128  
129 41 ▶ no warnings 'redefine'; ## no critic ProhibitNoWarnings
Subroutine BEGIN: called CC=1 SCAR=0.0
130 56 ▶ sub hex { ## no critic ProhibitBuiltinHomonyms
Subroutine hex: called CC=3 SCAR=11.1
Pod documented
131 56 my $self = shift;
132 56 my $name = shift;
133 56 my $rgb = $self->FETCH($name);
134 56 ▶ return unless defined $rgb; # this is the monkey line
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rgb 1 55 56
135 55 my $pre = shift;
136 0 ▶ unless (defined $pre) { $pre = ""; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pre) 0 55 55
137 55 return ($pre.$rgb);
138 }
139 }
140  
141 41 ▶no Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
142  
143 41 1;
144  
145  
146 # ABSTRACT: type library for Chart::OFC
147  
148 __END__
« OFC.pm ↑ Summary OFC/Role/OFCDataLines.pm »