| 1 | package SVG::Estimate::Role::ArgsWithUnits; | ||||||||||
| 2 | 9 | $SVG::Estimate::Role::ArgsWithUnits::VERSION = '1.0116'; | |||||||||
| 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.0116 | ||||||||||
| 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
| |||||||||||
| 28 | 15 | foreach my $param ($class->args_with_units) { | |||||||||
| 29 | 23 | ▶ | if ($args->{$param} =~ /\d\D+$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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; | |||||||||