| 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
| |||||||||||
| 18 | |||||||||||
| 19 | 7 | my $c = $self->get_errors(@_); | |||||||||
| 20 | |||||||||||
| 21 | 7 | ▶ | return @$c ? $c->[0] : (); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 28 | |||||||||||
| 29 | 276 | eval { my %x = %$arg }; | |||||||||
| 30 | 276 | ▶ | croak "options argument must be hash-ref" if $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | |||||||||||
| 32 | 276 | my $abs = $type =~ s/^\+//; | |||||||||
| 33 | 276 | my $not = 0; | |||||||||
| 34 | |||||||||||
| 35 | 276 | ▶ | if ( $type =~ /^Not_(\w+)$/i ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 4 | $type = $1; | |||||||||
| 37 | 4 | $not = 1; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 276 | my $class = $type; | |||||||||
| 41 | |||||||||||
| 42 | 276 | ▶ | if ( !$abs ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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__ | ||||||||||