lib/HTML/FormFu/Role/ContainsElementsSharedWithField.pm

filter: Statementstmt 100% 39 / 39 Branchbran 71.4% 10 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 91.6% 55 / 60 CC 8 SCAR 13.3
CC
8
Cov
92%
_require_constraint
6.0
get_error
3.0
BEGIN
1.0
CRAP 3.8
« lib/HTML/FormFu/Exception/Input.pm ↑ Summary lib/HTML/FormFu/Element/ComboBox.pm »
1 442 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Role::ContainsElementsSharedWithField;
4 # ABSTRACT: Role for constraints on elements and fields
5 442 $HTML::FormFu::Role::ContainsElementsSharedWithField::VERSION = '2.09';
6 442 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 442 ▶use HTML::FormFu::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
9 require_class
10 _merge_hashes
11 442 );
12 442 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 7 ▶sub get_error {
Subroutine get_error: called CC=3 SCAR=11.0
Pod undocumented
15 7 my $self = shift;
16  
17 7 ▶ return if !$self->form->submitted;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->form->submitted 0 7 7
18  
19 7 my $c = $self->get_errors(@_);
20  
21 7 ▶ return @$c ? $c->[0] : ();
Branch: 1 branch
BranchTrueFalseTotal
@$c ? : 5 2 7
22 }
23  
24 276 ▶sub _require_constraint {
Subroutine _require_constraint: called CC=6 SCAR=18.0
25 276 my ( $self, $type, $arg ) = @_;
26  
27 276 ▶ croak 'required arguments: $self, $type, \%options' if @_ != 3;
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 3 0 276 276
28  
29 276 eval { my %x = %$arg };
30 276 ▶ croak "options argument must be hash-ref" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 276 276
31  
32 276 my $abs = $type =~ s/^\+//;
33 276 my $not = 0;
34  
35 276 ▶ if ( $type =~ /^Not_(\w+)$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /^Not_(\w+)$/i) 4 272 276
36 4 $type = $1;
37 4 $not = 1;
38 }
39  
40 276 my $class = $type;
41  
42 276 ▶ if ( !$abs ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($abs) 276 0 276
43 276 $class = "HTML::FormFu::Constraint::$class";
44 }
45  
46 276 $type =~ s/^\+//;
47  
48 276 require_class($class);
49  
50 276 my $constraint = $class->new(
51 { type => $type,
52 not => $not,
53 parent => $self,
54 } );
55  
56 # handle default_args
57 276 my $parent = $self->parent;
58  
59 276 ▶ if ( exists $parent->default_args->{constraints}{$type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $parent->default_args->{"constraints"}{$type}) 1 275 276
60 1 $arg = _merge_hashes( $parent->default_args->{constraints}{$type}, $arg,
61 );
62 }
63  
64 276 $constraint->populate($arg);
65  
66 276 return $constraint;
67 }
68  
69 442 1;
70  
71 __END__
« lib/HTML/FormFu/Exception/Input.pm ↑ Summary lib/HTML/FormFu/Element/ComboBox.pm »