lib/SVG/Estimate/Role/ArgsWithUnits.pm

filter: Statementstmt 100% 20 / 20 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 96.4% 27 / 28 CC 4 SCAR 10.0
CC
4
Cov
96%
__ANON__
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.7
« lib/SVG/Estimate/Circle.pm ↑ Summary lib/SVG/Estimate/Path/Moveto.pm »
1 package SVG::Estimate::Role::ArgsWithUnits;
2 9 $SVG::Estimate::Role::ArgsWithUnits::VERSION = '1.0111';
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use Ouch;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 SVG::Estimate::Role::ArgsWithUnits - Validate a list of arguments that could contain units
10  
11 =head1 VERSION
12  
13 version 1.0111
14  
15 =head1 METHODS
16  
17 =head2 BUILDARGS ( )
18  
19 Validate the set of args from the class's C<args_with_units> method to make sure they don't have units
20  
21 =cut
22  
23 around BUILDARGS => sub {
24 15 ▶ my $orig = shift;
Subroutine __ANON__: called CC=4 SCAR=13.9
25 15 my $class = shift;
26 15 my @args = @_;
27 15 ▶ my $args = @args % 2 ? $args[0] : { @args };
Branch: 1 branch
BranchTrueFalseTotal
@args % 2 ? : 0 15 15
28 15 foreach my $param ($class->args_with_units) {
29 23 ▶ if ($args->{$param} =~ /\d\D+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{$param} =~ /\d\D+$/) 6 17 23
30 6 ouch 'units detected', "$param is not allowed to have units", $args->{$param};
31 }
32 }
33 ##Validate before the arguments are used
34 9 return $class->$orig($args);
35 9 };
36  
37  
38 9 1;
« lib/SVG/Estimate/Circle.pm ↑ Summary lib/SVG/Estimate/Path/Moveto.pm »