| 1 | 441 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 2 | |||||||||||||
| 3 | package HTML::FormFu::Role::FormAndElementMethods; | ||||||||||||
| 4 | # ABSTRACT: role for form and element methods | ||||||||||||
| 5 | 441 | $HTML::FormFu::Role::FormAndElementMethods::VERSION = '2.09'; | |||||||||||
| 6 | 441 | ▶ | use Moose::Role; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 441 | ▶ | use HTML::FormFu::Attribute qw( | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | mk_attrs | ||||||||||||
| 10 | mk_attr_accessors | ||||||||||||
| 11 | mk_inherited_accessors | ||||||||||||
| 12 | mk_inherited_merging_accessors | ||||||||||||
| 13 | 441 | ); | |||||||||||
| 14 | 441 | ▶ | use HTML::FormFu::Util qw( | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | require_class | ||||||||||||
| 16 | _merge_hashes | ||||||||||||
| 17 | 441 | ); | |||||||||||
| 18 | 441 | ▶ | use Carp qw( croak ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | 441 | ▶ | use Scalar::Util qw( blessed refaddr ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | |||||||||||||
| 21 | 441 | my @ATTRS = (qw( attributes )); | |||||||||||
| 22 | |||||||||||||
| 23 | 441 | __PACKAGE__->mk_attrs(@ATTRS); | |||||||||||
| 24 | |||||||||||||
| 25 | 441 | my @ATTR_ACCESSOR = (qw( title )); | |||||||||||
| 26 | |||||||||||||
| 27 | 441 | __PACKAGE__->mk_attr_accessors(@ATTR_ACCESSOR); | |||||||||||
| 28 | |||||||||||||
| 29 | 441 | my @INHERITED = qw( | |||||||||||
| 30 | render_method | ||||||||||||
| 31 | config_file_path | ||||||||||||
| 32 | ); | ||||||||||||
| 33 | |||||||||||||
| 34 | 441 | __PACKAGE__->mk_inherited_accessors(@INHERITED); | |||||||||||
| 35 | |||||||||||||
| 36 | 441 | my @MERGING = qw( | |||||||||||
| 37 | tt_args | ||||||||||||
| 38 | config_callback | ||||||||||||
| 39 | ); | ||||||||||||
| 40 | |||||||||||||
| 41 | 441 | __PACKAGE__->mk_inherited_merging_accessors(@MERGING); | |||||||||||
| 42 | |||||||||||||
| 43 | 441 | our @MULTIFORM_SHARED = ( @ATTRS, @ATTR_ACCESSOR, @INHERITED, @MERGING, ); | |||||||||||
| 44 | |||||||||||||
| 45 | 28 | ▶ | sub _require_deflator { | ||||||||||
|
Subroutine
_require_deflator: called CC=5 SCAR=16.3
| |||||||||||||
| 46 | 28 | my ( $self, $type, $opt ) = @_; | |||||||||||
| 47 | |||||||||||||
| 48 | 28 | ▶ | croak 'required arguments: $self, $type, \%options' if @_ != 3; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 49 | |||||||||||||
| 50 | 28 | eval { my %x = %$opt }; | |||||||||||
| 51 | 28 | ▶ | croak "options argument must be hash-ref" if $@; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 52 | |||||||||||||
| 53 | 28 | my $class = $type; | |||||||||||
| 54 | 28 | ▶ | if ( not $class =~ s/^\+// ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 55 | 27 | $class = "HTML::FormFu::Deflator::$class"; | |||||||||||
| 56 | } | ||||||||||||
| 57 | |||||||||||||
| 58 | 28 | $type =~ s/^\+//; | |||||||||||
| 59 | |||||||||||||
| 60 | 28 | require_class($class); | |||||||||||
| 61 | |||||||||||||
| 62 | 28 | my $object = $class->new( | |||||||||||
| 63 | { type => $type, | ||||||||||||
| 64 | parent => $self, | ||||||||||||
| 65 | } ); | ||||||||||||
| 66 | |||||||||||||
| 67 | # handle default_args | ||||||||||||
| 68 | 28 | my $parent = $self->parent; | |||||||||||
| 69 | |||||||||||||
| 70 | 28 | ▶ | if ( exists $parent->default_args->{deflators}{$type} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 71 | $opt | ||||||||||||
| 72 | 0 | = _merge_hashes( $parent->default_args->{deflators}{$type}, $opt, ); | |||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | 28 | $object->populate($opt); | |||||||||||
| 76 | |||||||||||||
| 77 | 28 | return $object; | |||||||||||
| 78 | } | ||||||||||||
| 79 | |||||||||||||
| 80 | 77 | ▶ | sub _require_filter { | ||||||||||
|
Subroutine
_require_filter: called CC=5 SCAR=16.5
| |||||||||||||
| 81 | 77 | my ( $self, $type, $opt ) = @_; | |||||||||||
| 82 | |||||||||||||
| 83 | 77 | ▶ | croak 'required arguments: $self, $type, \%options' if @_ != 3; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 84 | |||||||||||||
| 85 | 77 | eval { my %x = %$opt }; | |||||||||||
| 86 | 77 | ▶ | croak "options argument must be hash-ref" if $@; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 87 | |||||||||||||
| 88 | 77 | my $class = $type; | |||||||||||
| 89 | 77 | ▶ | if ( not $class =~ s/^\+// ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 90 | 77 | $class = "HTML::FormFu::Filter::$class"; | |||||||||||
| 91 | } | ||||||||||||
| 92 | |||||||||||||
| 93 | 77 | $type =~ s/^\+//; | |||||||||||
| 94 | |||||||||||||
| 95 | 77 | require_class($class); | |||||||||||
| 96 | |||||||||||||
| 97 | 77 | my $object = $class->new( | |||||||||||
| 98 | { type => $type, | ||||||||||||
| 99 | parent => $self, | ||||||||||||
| 100 | } ); | ||||||||||||
| 101 | |||||||||||||
| 102 | # handle default_args | ||||||||||||
| 103 | 77 | my $parent = $self->parent; | |||||||||||
| 104 | |||||||||||||
| 105 | 77 | ▶ | if ( exists $parent->default_args->{filters}{$type} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 106 | 0 | $opt = _merge_hashes( $parent->default_args->{filters}{$type}, $opt, ); | |||||||||||
| 107 | } | ||||||||||||
| 108 | |||||||||||||
| 109 | 77 | $object->populate($opt); | |||||||||||
| 110 | |||||||||||||
| 111 | 77 | return $object; | |||||||||||
| 112 | } | ||||||||||||
| 113 | |||||||||||||
| 114 | 34 | ▶ | sub _require_inflator { | ||||||||||
|
Subroutine
_require_inflator: called CC=5 SCAR=16.5
| |||||||||||||
| 115 | 34 | my ( $self, $type, $opt ) = @_; | |||||||||||
| 116 | |||||||||||||
| 117 | 34 | ▶ | croak 'required arguments: $self, $type, \%options' if @_ != 3; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 118 | |||||||||||||
| 119 | 34 | eval { my %x = %$opt }; | |||||||||||
| 120 | 34 | ▶ | croak "options argument must be hash-ref" if $@; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 121 | |||||||||||||
| 122 | 34 | my $class = $type; | |||||||||||
| 123 | 34 | ▶ | if ( not $class =~ s/^\+// ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 124 | 34 | $class = "HTML::FormFu::Inflator::$class"; | |||||||||||
| 125 | } | ||||||||||||
| 126 | |||||||||||||
| 127 | 34 | $type =~ s/^\+//; | |||||||||||
| 128 | |||||||||||||
| 129 | 34 | require_class($class); | |||||||||||
| 130 | |||||||||||||
| 131 | 34 | my $object = $class->new( | |||||||||||
| 132 | { type => $type, | ||||||||||||
| 133 | parent => $self, | ||||||||||||
| 134 | } ); | ||||||||||||
| 135 | |||||||||||||
| 136 | # handle default_args | ||||||||||||
| 137 | 34 | my $parent = $self->parent; | |||||||||||
| 138 | |||||||||||||
| 139 | 34 | ▶ | if ( exists $parent->default_args->{inflators}{$type} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 140 | $opt | ||||||||||||
| 141 | 0 | = _merge_hashes( $parent->default_args->{inflators}{$type}, $opt, ); | |||||||||||
| 142 | } | ||||||||||||
| 143 | |||||||||||||
| 144 | 34 | $object->populate($opt); | |||||||||||
| 145 | |||||||||||||
| 146 | 34 | return $object; | |||||||||||
| 147 | } | ||||||||||||
| 148 | |||||||||||||
| 149 | 6 | ▶ | sub _require_validator { | ||||||||||
|
Subroutine
_require_validator: called CC=5 SCAR=16.5
| |||||||||||||
| 150 | 6 | my ( $self, $type, $opt ) = @_; | |||||||||||
| 151 | |||||||||||||
| 152 | 6 | ▶ | croak 'required arguments: $self, $type, \%options' if @_ != 3; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 153 | |||||||||||||
| 154 | 6 | eval { my %x = %$opt }; | |||||||||||
| 155 | 6 | ▶ | croak "options argument must be hash-ref" if $@; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 156 | |||||||||||||
| 157 | 6 | my $class = $type; | |||||||||||
| 158 | 6 | ▶ | if ( not $class =~ s/^\+// ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 159 | 4 | $class = "HTML::FormFu::Validator::$class"; | |||||||||||
| 160 | } | ||||||||||||
| 161 | |||||||||||||
| 162 | 6 | $type =~ s/^\+//; | |||||||||||
| 163 | |||||||||||||
| 164 | 6 | require_class($class); | |||||||||||
| 165 | |||||||||||||
| 166 | 6 | my $object = $class->new( | |||||||||||
| 167 | { type => $type, | ||||||||||||
| 168 | parent => $self, | ||||||||||||
| 169 | } ); | ||||||||||||
| 170 | |||||||||||||
| 171 | # handle default_args | ||||||||||||
| 172 | 6 | my $parent = $self->parent; | |||||||||||
| 173 | |||||||||||||
| 174 | 6 | ▶ | if ( exists $parent->default_args->{validators}{$type} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 175 | 0 | %$opt = ( %{ $parent->default_args->{validators}{$type} }, %$opt ); | |||||||||||
| 176 | } | ||||||||||||
| 177 | |||||||||||||
| 178 | 6 | $object->populate($opt); | |||||||||||
| 179 | |||||||||||||
| 180 | 6 | return $object; | |||||||||||
| 181 | } | ||||||||||||
| 182 | |||||||||||||
| 183 | 5 | ▶ | sub _require_transformer { | ||||||||||
|
Subroutine
_require_transformer: called CC=5 SCAR=16.5
| |||||||||||||
| 184 | 5 | my ( $self, $type, $opt ) = @_; | |||||||||||
| 185 | |||||||||||||
| 186 | 5 | ▶ | croak 'required arguments: $self, $type, \%options' if @_ != 3; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 187 | |||||||||||||
| 188 | 5 | eval { my %x = %$opt }; | |||||||||||
| 189 | 5 | ▶ | croak "options argument must be hash-ref" if $@; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 190 | |||||||||||||
| 191 | 5 | my $class = $type; | |||||||||||
| 192 | 5 | ▶ | if ( not $class =~ s/^\+// ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 193 | 5 | $class = "HTML::FormFu::Transformer::$class"; | |||||||||||
| 194 | } | ||||||||||||
| 195 | |||||||||||||
| 196 | 5 | $type =~ s/^\+//; | |||||||||||
| 197 | |||||||||||||
| 198 | 5 | require_class($class); | |||||||||||
| 199 | |||||||||||||
| 200 | 5 | my $object = $class->new( | |||||||||||
| 201 | { type => $type, | ||||||||||||
| 202 | parent => $self, | ||||||||||||
| 203 | } ); | ||||||||||||
| 204 | |||||||||||||
| 205 | # handle default_args | ||||||||||||
| 206 | 5 | my $parent = $self->parent; | |||||||||||
| 207 | |||||||||||||
| 208 | 5 | ▶ | if ( exists $parent->default_args->{transformers}{$type} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 209 | $opt | ||||||||||||
| 210 | 0 | = _merge_hashes( $parent->default_args->{transformers}{$type}, | |||||||||||
| 211 | $opt, ); | ||||||||||||
| 212 | } | ||||||||||||
| 213 | |||||||||||||
| 214 | 5 | $object->populate($opt); | |||||||||||
| 215 | |||||||||||||
| 216 | 5 | return $object; | |||||||||||
| 217 | } | ||||||||||||
| 218 | |||||||||||||
| 219 | 2 | ▶ | sub _require_plugin { | ||||||||||
|
Subroutine
_require_plugin: called CC=4 SCAR=14.0
| |||||||||||||
| 220 | 2 | my ( $self, $type, $arg ) = @_; | |||||||||||
| 221 | |||||||||||||
| 222 | 2 | ▶ | croak 'required arguments: $self, $type, \%options' if @_ != 3; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 223 | |||||||||||||
| 224 | 2 | eval { my %x = %$arg }; | |||||||||||
| 225 | 2 | ▶ | croak "options argument must be hash-ref" if $@; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 226 | |||||||||||||
| 227 | 2 | my $abs = $type =~ s/^\+//; | |||||||||||
| 228 | 2 | my $class = $type; | |||||||||||
| 229 | |||||||||||||
| 230 | 2 | ▶ | if ( !$abs ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 231 | 2 | $class = "HTML::FormFu::Plugin::$class"; | |||||||||||
| 232 | } | ||||||||||||
| 233 | |||||||||||||
| 234 | 2 | $type =~ s/^\+//; | |||||||||||
| 235 | |||||||||||||
| 236 | 2 | require_class($class); | |||||||||||
| 237 | |||||||||||||
| 238 | 2 | my $plugin = $class->new( | |||||||||||
| 239 | { type => $type, | ||||||||||||
| 240 | parent => $self, | ||||||||||||
| 241 | } ); | ||||||||||||
| 242 | |||||||||||||
| 243 | 2 | $plugin->populate($arg); | |||||||||||
| 244 | |||||||||||||
| 245 | 2 | return $plugin; | |||||||||||
| 246 | } | ||||||||||||
| 247 | |||||||||||||
| 248 | 7 | ▶ | sub get_deflator { | ||||||||||
|
Subroutine
get_deflator: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 249 | 7 | my $self = shift; | |||||||||||
| 250 | |||||||||||||
| 251 | 7 | my $x = $self->get_deflators(@_); | |||||||||||
| 252 | |||||||||||||
| 253 | 7 | ▶ | return @$x ? $x->[0] : (); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 254 | } | ||||||||||||
| 255 | |||||||||||||
| 256 | 4 | ▶ | sub get_filter { | ||||||||||
|
Subroutine
get_filter: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||
| 257 | 4 | my $self = shift; | |||||||||||
| 258 | |||||||||||||
| 259 | 4 | my $x = $self->get_filters(@_); | |||||||||||
| 260 | |||||||||||||
| 261 | 4 | ▶ | return @$x ? $x->[0] : (); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 262 | } | ||||||||||||
| 263 | |||||||||||||
| 264 | 23 | ▶ | sub get_constraint { | ||||||||||
|
Subroutine
get_constraint: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 265 | 23 | my $self = shift; | |||||||||||
| 266 | |||||||||||||
| 267 | 23 | my $x = $self->get_constraints(@_); | |||||||||||
| 268 | |||||||||||||
| 269 | 23 | ▶ | return @$x ? $x->[0] : (); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 270 | } | ||||||||||||
| 271 | |||||||||||||
| 272 | 7 | ▶ | sub get_inflator { | ||||||||||
|
Subroutine
get_inflator: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 273 | 7 | my $self = shift; | |||||||||||
| 274 | |||||||||||||
| 275 | 7 | my $x = $self->get_inflators(@_); | |||||||||||
| 276 | |||||||||||||
| 277 | 7 | ▶ | return @$x ? $x->[0] : (); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 278 | } | ||||||||||||
| 279 | |||||||||||||
| 280 | 0 | ▶ | sub get_validator { | ||||||||||
|
Subroutine
get_validator: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 281 | 0 | my $self = shift; | |||||||||||
| 282 | |||||||||||||
| 283 | 0 | my $x = $self->get_validators(@_); | |||||||||||
| 284 | |||||||||||||
| 285 | 0 | ▶ | return @$x ? $x->[0] : (); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 286 | } | ||||||||||||
| 287 | |||||||||||||
| 288 | 0 | ▶ | sub get_transformer { | ||||||||||
|
Subroutine
get_transformer: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 289 | 0 | my $self = shift; | |||||||||||
| 290 | |||||||||||||
| 291 | 0 | my $x = $self->get_transformers(@_); | |||||||||||
| 292 | |||||||||||||
| 293 | 0 | ▶ | return @$x ? $x->[0] : (); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 294 | } | ||||||||||||
| 295 | |||||||||||||
| 296 | 0 | ▶ | sub get_plugin { | ||||||||||
|
Subroutine
get_plugin: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 297 | 0 | my $self = shift; | |||||||||||
| 298 | |||||||||||||
| 299 | 0 | my $x = $self->get_plugins(@_); | |||||||||||
| 300 | |||||||||||||
| 301 | 0 | ▶ | return @$x ? $x->[0] : (); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 302 | } | ||||||||||||
| 303 | |||||||||||||
| 304 | 855 | ▶ | sub model_config { | ||||||||||
|
Subroutine
model_config: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 305 | 855 | my ( $self, $config ) = @_; | |||||||||||
| 306 | |||||||||||||
| 307 | 855 | ▶ | $self->{model_config} ||= {}; | ||||||||||
|
Condition100%2/2
$self->{"model_config"} ||= {}
MC/DC100%1/1
$self->{"model_config"} ||= {}
$self->{"model_config"}
Truth table100%2/2
A
A= $self->{"model_config"}
| |||||||||||||
| 308 | |||||||||||||
| 309 | 855 | $self->{model_config} = _merge_hashes( $self->{model_config}, $config ); | |||||||||||
| 310 | |||||||||||||
| 311 | 855 | return $self->{model_config}; | |||||||||||
| 312 | } | ||||||||||||
| 313 | |||||||||||||
| 314 | 85 | ▶ | sub _string_equals { | ||||||||||
|
Subroutine
_string_equals: called CC=2 SCAR=6.9
| |||||||||||||
| 315 | 85 | my ( $a, $b ) = @_; | |||||||||||
| 316 | |||||||||||||
| 317 | 85 | ▶ | return blessed($b) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 318 | ? ( refaddr($a) eq refaddr($b) ) | ||||||||||||
| 319 | : ( "$a" eq "$b" ); | ||||||||||||
| 320 | } | ||||||||||||
| 321 | |||||||||||||
| 322 | 202 | ▶ | sub _object_equals { | ||||||||||
|
Subroutine
_object_equals: called CC=2 SCAR=7.2
| |||||||||||||
| 323 | 202 | my ( $a, $b ) = @_; | |||||||||||
| 324 | |||||||||||||
| 325 | 202 | ▶ | return blessed($b) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 326 | ? ( refaddr($a) eq refaddr($b) ) | ||||||||||||
| 327 | : undef; | ||||||||||||
| 328 | } | ||||||||||||
| 329 | |||||||||||||
| 330 | 441 | 1; | |||||||||||
| 331 | |||||||||||||
| 332 | __END__ | ||||||||||||