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