| 1 | package HTML::FormHandler; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: HTML forms using Moose | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 147 | $HTML::FormHandler::VERSION = '0.410002'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 147 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 147 | extends 'HTML::FormHandler::Base'; # to make some methods overridable by roles | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 147 | with 'HTML::FormHandler::Model', 'HTML::FormHandler::Fields', | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 'HTML::FormHandler::BuildFields', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 'HTML::FormHandler::TraitFor::I18N'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 147 | with 'HTML::FormHandler::InitResult'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 147 | with 'HTML::FormHandler::Widget::ApplyRole'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 147 | with 'HTML::FormHandler::Traits'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 147 | with 'HTML::FormHandler::Blocks'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 147 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 147 | ▶ | use Class::MOP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 147 | ▶ | use HTML::FormHandler::Result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 147 | ▶ | use HTML::FormHandler::Field; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 147 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 147 | ▶ | use MooseX::Types::LoadableClass qw/ LoadableClass /; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 147 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 147 | ▶ | use HTML::FormHandler::Merge ('merge'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 147 | ▶ | use Sub::Name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 147 | ▶ | use Data::Clone; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 147 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # for consistency in api with field nodes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 17789 | ▶ | sub form { shift } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
form: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub is_form { 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_form: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub has_form { 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_form: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # Moose attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | has 'name' => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 198 | ▶ | default => sub { return 'form' . int( rand 1000 ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 147 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 4219 | ▶ | sub full_name { '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
full_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 10 | ▶ | sub full_accessor { '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
full_accessor: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 147 | has 'parent' => ( is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 147 | has 'result' => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | isa => 'HTML::FormHandler::Result', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | writer => '_set_result', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | clearer => 'clear_result', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | builder => 'build_result', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | predicate => 'has_result', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | handles => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 'input', '_set_input', '_clear_input', 'has_input', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 'value', '_set_value', '_clear_value', 'has_value', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 'add_result', 'results', 'validated', 'ran_validation', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 'is_valid', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 'form_errors', 'all_form_errors', 'push_form_errors', 'clear_form_errors', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 'has_form_errors', 'num_form_errors', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 569 | ▶ | sub build_result { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_result: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 569 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 569 | my $result_class = 'HTML::FormHandler::Result'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 569 | ▶ | if ( $self->widget_form ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 569 | my $role = $self->get_widget_role( $self->widget_form, 'Form' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 569 | $result_class = $result_class->with_traits( $role ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 569 | my $result = $result_class->new( name => $self->name, form => $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 569 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | has 'index' => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | is => 'ro', isa => 'HashRef[HTML::FormHandler::Field]', traits => ['Hash'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 260 | ▶ | default => sub {{}}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 147 | handles => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | add_to_index => 'set', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | field_from_index => 'get', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | field_in_index => 'exists', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | has '_repeatable_fields' => ( is => 'rw', isa => 'ArrayRef', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 260 | ▶ | traits => ['Array'], default => sub {[]}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 147 | handles => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | add_repeatable_field => 'push', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | has_repeatable_fields => 'count', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | all_repeatable_fields => 'elements', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | has 'field_traits' => ( is => 'ro', traits => ['Array'], isa => 'ArrayRef', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 257 | ▶ | default => sub {[]}, handles => { 'has_field_traits' => 'count' } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | has 'widget_name_space' => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | isa => 'HFH::ArrayRefStr', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | traits => ['Array'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 254 | ▶ | default => sub {[]}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 147 | coerce => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | handles => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | add_widget_name_space => 'push', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # it only really makes sense to set these before widget_form is applied in BUILD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 147 | has 'widget_form' => ( is => 'ro', isa => 'Str', default => 'Simple', writer => 'set_widget_form' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 147 | has 'widget_wrapper' => ( is => 'ro', isa => 'Str', default => 'Simple', writer => 'set_widget_wrapper' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 147 | has 'do_form_wrapper' => ( is => 'rw', builder => 'build_do_form_wrapper' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 249 | ▶ | sub build_do_form_wrapper { 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_do_form_wrapper: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 147 | has 'no_widgets' => ( is => 'ro', isa => 'Bool' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 147 | has 'no_preload' => ( is => 'ro', isa => 'Bool' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 147 | has 'no_update' => ( is => 'rw', isa => 'Bool', clearer => 'clear_no_update' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | has 'active' => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | traits => ['Array'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 260 | ▶ | default => sub {[]}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 147 | handles => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | add_active => 'push', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | has_active => 'count', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | clear_active => 'clear', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | has 'inactive' => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | traits => ['Array'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 259 | ▶ | default => sub {[]}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 147 | handles => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | add_inactive => 'push', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | has_inactive => 'count', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | clear_inactive => 'clear', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # object with which to initialize | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 147 | has 'init_object' => ( is => 'rw', clearer => 'clear_init_object' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | has 'update_field_list' => ( is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | isa => 'HashRef', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 260 | ▶ | default => sub {{}}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 147 | traits => ['Hash'], | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | handles => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | clear_update_field_list => 'clear', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | has_update_field_list => 'count', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | set_update_field_list => 'set', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 260 | ▶ | has 'defaults' => ( is => 'rw', isa => 'HashRef', default => sub {{}}, traits => ['Hash'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | handles => { has_defaults => 'count', clear_defaults => 'clear' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 147 | has 'use_defaults_over_obj' => ( is => 'rw', isa => 'Bool', clearer => 'clear_use_defaults_over_obj' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 147 | has 'use_init_obj_over_item' => ( is => 'rw', isa => 'Bool', clearer => 'clear_use_init_obj_over_item' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 147 | has 'use_init_obj_when_no_accessor_in_item' => ( is => 'rw', isa => 'Bool' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 147 | has 'use_fields_for_input_without_param' => ( is => 'rw', isa => 'Bool' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # flags | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 147 | has [ 'verbose', 'processed', 'did_init_obj' ] => ( isa => 'Bool', is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 147 | has 'user_data' => ( isa => 'HashRef', is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 147 | has 'ctx' => ( is => 'rw', weak_ref => 1, clearer => 'clear_ctx' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 147 | has 'html_prefix' => ( isa => 'Bool', is => 'ro' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 147 | has 'active_column' => ( isa => 'Str', is => 'ro' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 147 | has 'http_method' => ( isa => 'Str', is => 'ro', default => 'post' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 147 | has 'enctype' => ( is => 'rw', isa => 'Str' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 147 | has 'error_message' => ( is => 'rw', predicate => 'has_error_message', clearer => 'clear_error_message' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 147 | has 'success_message' => ( is => 'rw', predicate => 'has_success_message', clearer => 'clear_success_message' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 147 | has 'info_message' => ( is => 'rw', predicate => 'has_info_message', clearer => 'clear_info_message' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # deprecated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 147 | has 'style' => ( isa => 'Str', is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 147 | has 'is_html5' => ( isa => 'Bool', is => 'ro', default => 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # deprecated. use form_element_attr instead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | has 'html_attr' => ( is => 'rw', traits => ['Hash'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 260 | ▶ | default => sub { {} }, handles => { has_html_attr => 'count', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | set_html_attr => 'set', delete_html_attr => 'delete' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | trigger => \&_html_attr_set, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | sub _html_attr_set { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_html_attr_set: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | my $class = delete $value->{class}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $self->form_element_attr($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | $self->add_form_element_class if $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # create the attributes and methods for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # form_element_attr, build_form_element_attr, form_element_class, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # form_wrapper_attr, build_form_wrapper_atrr, form_wrapper_class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 147 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 147 | foreach my $attr ('form_wrapper', 'form_element' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 294 | my $add_meth = "add_${attr}_class"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 294 | has "${attr}_attr" => ( is => 'rw', traits => ['Hash'], | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | builder => "build_${attr}_attr", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | handles => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | "has_${attr}_attr" => 'count', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | "get_${attr}_attr" => 'get', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | "set_${attr}_attr" => 'set', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | "delete_${attr}_attr" => 'delete', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | "exists_${attr}_attr" => 'exists', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # create builders for _attr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 294 | my $attr_builder = __PACKAGE__ . "::build_${attr}_attr"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 172 | ▶ | *$attr_builder = subname $attr_builder, sub {{}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_form_element_attr: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # create the 'class' slots | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 294 | has "${attr}_class" => ( is => 'rw', isa => 'HFH::ArrayRefStr', | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | traits => ['Array'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | coerce => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | builder => "build_${attr}_class", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | handles => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | "has_${attr}_class" => 'count', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | "_add_${attr}_class" => 'push', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # create builders for classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 294 | my $class_builder = __PACKAGE__ . "::build_${attr}_class"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | *$class_builder = subname $class_builder, sub {[]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Subroutine
build_form_element_class: called CC=1 SCAR=0.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # create wrapper for add_to_ to accept arrayref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 294 | my $add_to_class = __PACKAGE__ . "::add_${attr}_class"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 294 | my $_add_meth = __PACKAGE__ . "::_add_${attr}_class"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # create add method that takes an arrayref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | *$add_to_class = subname $add_to_class, sub { shift->$_add_meth((ref $_[0] eq 'ARRAY' ? @{$_[0]} : @_)); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 294 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 88 | ▶ | sub attributes { shift->form_element_attributes(@_) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attributes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 88 | ▶ | sub form_element_attributes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
form_element_attributes: called CC=8 SCAR=21.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 88 | my ( $self, $result ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 88 | ▶ | $result ||= $self->result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$result ||= $self->result
MC/DC0%0/2
$result ||= $self->result
$result
$self->result
Truth table66%2/3
A ||= B
A= $resultB= $self->result
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 88 | my $attr = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 88 | $attr->{id} = $self->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 88 | ▶ | $attr->{action} = $self->action if $self->action; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 88 | ▶ | $attr->{method} = $self->http_method if $self->http_method; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 88 | ▶ | $attr->{enctype} = $self->enctype if $self->enctype; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 88 | ▶ | $attr->{style} = $self->style if $self->style; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 88 | $attr = {%$attr, %{$self->form_element_attr}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 88 | my $class = [@{$self->form_element_class}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 88 | ▶ | $attr->{class} = $class if @$class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 88 | my $mod_attr = $self->html_attributes($self, 'form_element', $attr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 88 | ▶ | return ref $mod_attr eq 'HASH' ? $mod_attr : $attr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 15 | ▶ | sub form_wrapper_attributes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
form_wrapper_attributes: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 15 | my ( $self, $result ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 15 | ▶ | $result ||= $self->result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$result ||= $self->result
MC/DC0%0/2
$result ||= $self->result
$result
$self->result
Truth table33%1/3
A ||= B
A= $resultB= $self->result
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 15 | my $attr = {%{$self->form_wrapper_attr}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 15 | my $class = [@{$self->form_wrapper_class}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 15 | ▶ | $attr->{class} = $class if @$class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 15 | my $mod_attr = $self->html_attributes($self, 'form_wrapper', $attr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 15 | ▶ | return ref $mod_attr eq 'HASH' ? $mod_attr : $attr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 1426 | ▶ | sub html_attributes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
html_attributes: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 1426 | my ( $self, $obj, $type, $attrs, $result ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # deprecated 'field_html_attributes'; name changed, remove eventually | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 1426 | ▶ | if( $self->can('field_html_attributes') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | $attrs = $self->field_html_attributes( $obj, $type, $attrs, $result ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 1426 | return $attrs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 2289 | ▶ | sub has_flag { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_flag: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 2289 | my ( $self, $flag_name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 2289 | ▶ | return unless $self->can($flag_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 974 | return $self->$flag_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 147 | has 'form_tags' => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | traits => ['Hash'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | isa => 'HashRef', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | builder => 'build_form_tags', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | handles => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | _get_tag => 'get', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | set_tag => 'set', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | tag_exists => 'exists', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | has_tag => 'exists', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 247 | ▶ | sub build_form_tags {{}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_form_tags: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 682 | ▶ | sub get_tag { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_tag: called CC=6 SCAR=24.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 682 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 682 | ▶ | return '' unless $self->tag_exists($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 46 | my $tag = $self->_get_tag($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 46 | ▶ | return $self->$tag if ref $tag eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 46 | ▶ | return $tag unless $tag =~ /^%/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ( my $block_name = $tag ) =~ s/^%//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | return $self->form->block($block_name)->render | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->form and $self->form->block_exists($block_name)
MC/DC0%0/2
$self->form and $self->form->block_exists($block_name)
$self->form
$self->form->block_exists($block_name)
Truth table0%0/3
A and B
A= $self->formB= $self->form->block_exists($block_name)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | if ( $self->form && $self->form->block_exists($block_name) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | has 'for_js' => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | isa => 'HashRef', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | traits => ['Hash'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 260 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 147 | handles => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | set_for_js => 'set', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | has_for_js => 'count', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | clear_for_js => 'clear', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 147 | has 'action' => ( is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 147 | has 'posted' => ( is => 'rw', isa => 'Bool', clearer => 'clear_posted', predicate => 'has_posted' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | has 'params' => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | traits => ['Hash'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | isa => 'HashRef', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 260 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 368 | ▶ | trigger => sub { shift->_munge_params(@_) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 147 | handles => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | set_param => 'set', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | get_param => 'get', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | clear_params => 'clear', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | has_params => 'count', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | sub submitted { shift->has_params } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
submitted: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 147 | has 'dependency' => ( isa => 'ArrayRef', is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | has '_required' => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | traits => ['Array'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | isa => 'ArrayRef[HTML::FormHandler::Field]', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 260 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 147 | handles => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | clear_required => 'clear', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | add_required => 'push', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | # these messages could apply to either fields or form | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 147 | has 'messages' => ( is => 'rw', | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | isa => 'HashRef', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | traits => ['Hash'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | builder => 'build_messages', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | handles => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | '_get_form_message' => 'get', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | '_has_form_message' => 'exists', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 'set_message' => 'set', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 259 | ▶ | sub build_messages { {} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_messages: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 147 | my $class_messages = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | sub get_class_messages { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_class_messages: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | return $class_messages; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | sub get_message { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_message: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | my ( $self, $msg ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | return $self->_get_form_message($msg) if $self->_has_form_message($msg); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | return $self->get_class_messages->{$msg}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | sub all_messages { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all_messages: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | return { %{$self->get_class_messages}, %{$self->messages} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 147 | has 'params_class' => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | isa => LoadableClass, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | coerce => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | default => 'HTML::FormHandler::Params', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 147 | has 'params_args' => ( is => 'ro', isa => 'ArrayRef' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 260 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=4 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 260 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 260 | ▶ | if ( scalar @_ == 1 && ref( $_[0]) ne 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
scalar @_ == 1 and ref $_[0] ne "HASH"
MC/DC0%0/2
scalar @_ == 1 and ref $_[0] ne "HASH"
scalar @_ == 1
ref $_[0] ne "HASH"
Truth table66%2/3
A and B
A= scalar @_ == 1B= ref $_[0] ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | my $arg = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | return blessed($arg) ? { item => $arg } : { item_id => $arg }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 260 | return $class->SUPER::BUILDARGS(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 260 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=14 SCAR=27.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 260 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 260 | $self->before_build; # hook to allow customizing forms | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | # HTML::FormHandler::Widget::Form::Simple is applied in Base | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 260 | ▶ | $self->apply_widget_role( $self, $self->widget_form, 'Form' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->no_widgets or $self->widget_form eq "Simple"
MC/DC50%1/2
$self->no_widgets or $self->widget_form eq "Simple"
$self->no_widgets
$self->widget_form eq "Simple"
Truth table66%2/3
A or B
A= $self->no_widgetsB= $self->widget_form eq "Simple"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | unless ( $self->no_widgets || $self->widget_form eq 'Simple' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 260 | $self->_build_fields; # create the form fields (BuildFields.pm) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 257 | ▶ | $self->build_active if $self->has_active || $self->has_inactive || $self->has_flag('is_wizard'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$self->has_active or $self->has_inactive or $self->has_flag("is_wizard")
$self->has_active or $self->has_inactive
MC/DC66%2/3
$self->has_active or $self->has_inactive or $self->has_flag("is_wizard")
$self->has_active
$self->has_inactive
$self->has_flag("is_wizard")
Truth table75%3/4
A or B or C
A= $self->has_activeB= $self->has_inactiveC= $self->has_flag("is_wizard")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 257 | $self->after_build; # hook for customizing | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 257 | ▶ | return if defined $self->item_id && !$self->item; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->item_id and not $self->item
MC/DC0%0/2
defined $self->item_id and not $self->item
defined $self->item_id
not $self->item
Truth table33%1/3
A and not(B)
A= defined $self->item_idB= not $self->item
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | # Load values from object (if any) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | # Would rather not load results at all here, but skipping it breaks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | # existing apps that perform certain actions between 'new' and 'process'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | # Added fudge flag no_preload to enable skipping. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | # A well-behaved program that always does ->process shouldn't need this preloading. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 257 | ▶ | unless( $self->no_preload ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 256 | ▶ | if ( my $init_object = $self->use_init_obj_over_item ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
$self->init_object or $self->item
$self->item or $self->init_object
MC/DC0%0/2
$self->init_object or $self->item
$self->init_object
$self->item
MC/DC100%2/2
$self->item or $self->init_object
$self->item
$self->init_object
Truth table0%0/3
A or B
A= $self->init_objectB= $self->item
Truth table100%3/3
A or B
A= $self->itemB= $self->init_object
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | ($self->init_object || $self->item) : ( $self->item || $self->init_object ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 10 | $self->_result_from_object( $self->result, $init_object ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 246 | $self->_result_from_fields( $self->result ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 257 | ▶ | $self->dump_fields if $self->verbose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 257 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 259 | ▶ | sub before_build {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
before_build: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 257 | ▶ | sub after_build {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
after_build: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 285 | ▶ | sub process { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 285 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 285 | ▶ | warn "HFH: process ", $self->name, "\n" if $self->verbose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 285 | ▶ | $self->clear if $self->processed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 285 | $self->setup_form(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 285 | ▶ | $self->validate_form if $self->posted; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 285 | ▶ | $self->update_model if ( $self->validated && !$self->no_update ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->validated and not $self->no_update
MC/DC100%2/2
$self->validated and not $self->no_update
$self->validated
not $self->no_update
Truth table100%3/3
A and not(B)
A= $self->validatedB= not $self->no_update
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 285 | ▶ | $self->after_update_model if ( $self->validated && !$self->no_update ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->validated and not $self->no_update
MC/DC100%2/2
$self->validated and not $self->no_update
$self->validated
not $self->no_update
Truth table100%3/3
A and not(B)
A= $self->validatedB= not $self->no_update
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 285 | ▶ | $self->dump_fields if $self->verbose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 285 | $self->processed(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 285 | return $self->validated; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 12 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 12 | $self->setup_form(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 12 | ▶ | $self->validate_form if $self->posted; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 12 | ▶ | $self->update_model if ( $self->validated && !$self->no_update );; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->validated and not $self->no_update
MC/DC50%1/2
$self->validated and not $self->no_update
$self->validated
not $self->no_update
Truth table66%2/3
A and not(B)
A= $self->validatedB= not $self->no_update
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 12 | my $result = $self->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 12 | $self->clear; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 12 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 97 | ▶ | sub after_update_model { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
after_update_model: called CC=13 SCAR=25.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 97 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | # This an attempt to reload the repeatable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # relationships after the database is updated, so that we get the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | # primary keys of the repeatable elements. Otherwise, if a form | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | # is re-presented, repeatable elements without primary keys may | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | # be created again. There is no reliable way to connect up | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | # existing repeatable elements with their db-created primary keys. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 97 | ▶ | if ( $self->has_repeatable_fields && $self->item ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->has_repeatable_fields and $self->item
MC/DC100%2/2
$self->has_repeatable_fields and $self->item
$self->has_repeatable_fields
$self->item
Truth table100%3/3
A and B
A= $self->has_repeatable_fieldsB= $self->item
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 2 | foreach my $field ( $self->all_repeatable_fields ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 4 | ▶ | next unless $field->is_active; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # Check to see if there are any repeatable subfields with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | # null primary keys, so we can skip reloading for the case | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | # where all repeatables have primary keys. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 4 | my $needs_reload = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 4 | foreach my $sub_field ( $field->fields ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 9 | ▶ | if ( $sub_field->has_flag('is_compound') && $sub_field->has_primary_key ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$sub_field->has_flag("is_compound") and $sub_field->has_primary_key
MC/DC100%2/2
$sub_field->has_flag("is_compound") and $sub_field->has_primary_key
$sub_field->has_flag("is_compound")
$sub_field->has_primary_key
Truth table100%3/3
A and B
A= $sub_field->has_flag("is_compound")B= $sub_field->has_primary_key
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 1 | foreach my $pk_field ( @{ $sub_field->primary_key } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 1 | ▶ | $needs_reload++ unless $pk_field->fif; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 1 | ▶ | last if $needs_reload; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 4 | ▶ | next unless $needs_reload; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 1 | my @names = split( /\./, $field->full_name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 1 | my $rep_item = $self->find_sub_item( $self->item, \@names ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | # $rep_item is a single row or an array of rows or undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | # If we found a database item for the repeatable, replace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | # the existing result with a result derived from the item. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 1 | ▶ | if ( ref $rep_item ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 1 | my $parent = $field->parent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 1 | my $result = $field->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 1 | $field->init_state; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 1 | my $new_result = $field->_result_from_object( $result, $rep_item ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | # find index of existing result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 1 | ▶ | my $index = $parent->result->find_result_index( sub { $_ == $result } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | # replace existing result with new result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 1 | $parent->result->set_result_at_index( $index, $new_result ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | ▶ | sub db_validate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
db_validate: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | my $fif = $self->fif; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | $self->process($fif); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | return $self->validated; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 117 | ▶ | sub clear { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 117 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 117 | $self->clear_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 117 | $self->clear_params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 117 | $self->clear_posted; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 117 | $self->clear_item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 117 | $self->clear_init_object; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 117 | $self->clear_ctx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 117 | $self->processed(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 117 | $self->did_init_obj(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 117 | $self->clear_result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 117 | $self->clear_use_defaults_over_obj; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 117 | $self->clear_use_init_obj_over_item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 117 | $self->clear_no_update; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 117 | $self->clear_info_message; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 117 | $self->clear_for_js; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 13 | ▶ | sub values { shift->value } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
values: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | # deprecated? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 1 | ▶ | sub error_field_names { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error_field_names: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 1 | my @error_fields = $self->error_fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 1 | return map { $_->name } @error_fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 8 | ▶ | sub errors { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errors: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 8 | my @error_fields = $self->error_fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 8 | my @errors = $self->all_form_errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 8 | push @errors, map { $_->all_errors } @error_fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 8 | return @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 1 | ▶ | sub errors_by_id { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errors_by_id: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 1 | my %errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 1 | $errors{$_->id} = [$_->all_errors] for $self->error_fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 1 | return \%errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 1 | ▶ | sub errors_by_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errors_by_name: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 1 | my %errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 1 | $errors{$_->html_name} = [$_->all_errors] for $self->error_fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 1 | return \%errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 177 | ▶ | sub build_errors { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_errors: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 177 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | # this puts the errors in the result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 177 | foreach my $err_res (@{$self->result->error_results}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 103 | $self->result->_push_errors($err_res->all_errors); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | ▶ | sub uuid { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uuid: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | my $form = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | require Data::UUID; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | my $uuid = Data::UUID->new->create_str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | return qq[<input type="hidden" name="form_uuid" value="$uuid">]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 177 | ▶ | sub validate_form { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_form: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 177 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 177 | my $params = $self->params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 177 | $self->_set_dependency; # set required dependencies | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 177 | $self->_fields_validate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 177 | $self->validate; # empty method for users | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 177 | $self->validate_model; # model specific validation | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 177 | $self->fields_set_value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 177 | $self->build_errors; # move errors to result | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 177 | $self->_clear_dependency; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 177 | $self->clear_posted; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 177 | $self->ran_validation(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 177 | ▶ | $self->dump_validated if $self->verbose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 177 | return $self->validated; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 170 | ▶ | sub validate { 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 20 | ▶ | sub has_errors { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_errors: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 20 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 20 | ▶ | return $self->has_error_fields || $self->has_form_errors; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->has_error_fields || $self->has_form_errors
MC/DC100%2/2
$self->has_error_fields || $self->has_form_errors
$self->has_error_fields
$self->has_form_errors
Truth table100%3/3
A || B
A= $self->has_error_fieldsB= $self->has_form_errors
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 6 | ▶ | sub num_errors { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
num_errors: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 6 | return $self->num_error_fields + $self->num_form_errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | ▶ | sub get_errors { shift->errors } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_errors: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 297 | ▶ | sub setup_form { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setup_form: called CC=16 SCAR=28.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 297 | my ( $self, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 297 | ▶ | if ( @args == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 80 | $self->params( $args[0] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | elsif ( @args > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 182 | my $hashref = {@args}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 182 | ▶ | while ( my ( $key, $value ) = each %{$hashref} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 252 | ▶ | confess "invalid attribute '$key' passed to setup_form" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | unless $self->can($key); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 252 | $self->$key($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 297 | ▶ | if ( $self->item_id && !$self->item ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->item_id and not $self->item
MC/DC0%0/2
$self->item_id and not $self->item
$self->item_id
not $self->item
Truth table66%2/3
A and not(B)
A= $self->item_idB= not $self->item
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | $self->item( $self->build_item ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 297 | $self->clear_result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 297 | $self->set_active; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 297 | $self->update_fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | # initialization of Repeatable fields and Select options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | # will be done in _result_from_object when there's an initial object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | # in _result_from_input when there are params | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | # and by _result_from_fields for empty forms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 297 | ▶ | $self->posted(1) if ( $self->has_params && !$self->has_posted ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->has_params and not $self->has_posted
MC/DC100%2/2
$self->has_params and not $self->has_posted
$self->has_params
not $self->has_posted
Truth table100%3/3
A and not(B)
A= $self->has_paramsB= not $self->has_posted
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 297 | ▶ | if ( !$self->did_init_obj ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 297 | ▶ | if ( my $init_object = $self->use_init_obj_over_item ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%4/6
$self->init_object or $self->item
$self->item or $self->init_object
MC/DC0%0/2
$self->init_object or $self->item
$self->init_object
$self->item
MC/DC100%2/2
$self->item or $self->init_object
$self->item
$self->init_object
Truth table33%1/3
A or B
A= $self->init_objectB= $self->item
Truth table100%3/3
A or B
A= $self->itemB= $self->init_object
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | ($self->init_object || $self->item) : ( $self->item || $self->init_object ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 55 | $self->_result_from_object( $self->result, $init_object ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | elsif ( !$self->posted ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | # no initial object. empty form must be initialized | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 76 | $self->_result_from_fields( $self->result ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | # if params exist and if posted flag is either not set or set to true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 297 | my $params = clone( $self->params ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 297 | ▶ | if ( $self->posted ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 177 | $self->clear_result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 177 | $self->_result_from_input( $self->result, $params, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | # if active => [...] is set at process time, set 'active' flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 293 | ▶ | sub set_active { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_active: called CC=7 SCAR=19.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 293 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 293 | ▶ | if( $self->has_active ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 1 | foreach my $fname (@{$self->active}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 1 | my $field = $self->field($fname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 1 | ▶ | if ( $field ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 1 | $field->_active(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | warn "field $fname not found to set active"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 1 | $self->clear_active; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 293 | ▶ | if( $self->has_inactive ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 1 | foreach my $fname (@{$self->inactive}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 1 | my $field = $self->field($fname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 1 | ▶ | if ( $field ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 1 | $field->_active(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | warn "field $fname not found to set inactive"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 1 | $self->clear_inactive; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | # if active => [...] is set at build time, remove 'inactive' flags | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 1 | ▶ | sub build_active { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_active: called CC=7 SCAR=26.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 1 | ▶ | if( $self->has_active ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | foreach my $fname (@{$self->active}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | my $field = $self->field($fname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | ▶ | if( $field ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | $field->clear_inactive; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | warn "field $fname not found to set active"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | $self->clear_active; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 1 | ▶ | if( $self->has_inactive ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 1 | foreach my $fname (@{$self->inactive}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 1 | my $field = $self->field($fname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 1 | ▶ | if( $field ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 1 | $field->inactive(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | warn "field $fname not found to set inactive"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 1 | $self->clear_inactive; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 76 | ▶ | sub fif { shift->fields_fif(@_) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fif: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | # this is subclassed by the model, which may | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | # do a lot more than this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 257 | ▶ | sub init_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_value: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 257 | my ( $self, $field, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 257 | $field->init_value($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 257 | $field->_set_value($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 177 | ▶ | sub _set_dependency { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_dependency: called CC=12 SCAR=26.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 177 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 177 | ▶ | my $depends = $self->dependency || return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->dependency || (return)
MC/DC100%1/1
$self->dependency || (return)
$self->dependency
Truth table100%2/2
A
A= $self->dependency
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 9 | my $params = $self->params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 9 | for my $group (@$depends) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 10 | ▶ | next if @$group < 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | # process a group of fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 10 | for my $name (@$group) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | # is there a value? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 27 | my $value = $params->{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 27 | ▶ | next unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | # The exception is a boolean can be zero which we count as not set. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | # This is to allow requiring a field when a boolean is true. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 2 | my $field = $self->field($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 2 | ▶ | next if $self->field($name)->type eq 'Boolean' && $value == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->field($name)->type eq "Boolean" and $value == 0
MC/DC0%0/2
$self->field($name)->type eq "Boolean" and $value == 0
$self->field($name)->type eq "Boolean"
$value == 0
Truth table33%1/3
A and B
A= $self->field($name)->type eq "Boolean"B= $value == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 2 | ▶ | next unless HTML::FormHandler::Field::has_some_value($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | # one field was found non-blank, so set all to required | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 2 | for (@$group) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 6 | my $field = $self->field($_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 6 | ▶ | next unless $field && !$field->required; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$field and not $field->required
MC/DC0%0/2
$field and not $field->required
$field
not $field->required
Truth table33%1/3
A and not(B)
A= $fieldB= not $field->required
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 6 | $self->add_required($field); # save for clearing later. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 6 | $field->required(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 2 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 177 | ▶ | sub _clear_dependency { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_clear_dependency: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 177 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 177 | $_->required(0) for @{$self->_required}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 177 | $self->clear_required; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | ▶ | sub peek { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
peek: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | my $string = "Form " . $self->name . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | my $indent = ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | foreach my $field ( $self->sorted_fields ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | $string .= $field->peek( $indent ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | return $string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 368 | ▶ | sub _munge_params { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_munge_params: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 368 | my ( $self, $params, $attr ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 368 | ▶ | my $_fix_params = $self->params_class->new( @{ $self->params_args || [] } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->params_args || []
MC/DC0%0/1
$self->params_args || []
$self->params_args
Truth table50%1/2
A
A= $self->params_args
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 368 | my $new_params = $_fix_params->expand_hash($params); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 368 | ▶ | if ( $self->html_prefix ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 6 | $new_params = $new_params->{ $self->name }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 368 | ▶ | $new_params = {} if !defined $new_params; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 368 | $self->{params} = $new_params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 1 | ▶ | sub params_to_values { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
params_to_values: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 1 | my ( $self, $params ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 1 | ▶ | my $_fix_params = $self->params_class->new( @{ $self->params_args || [] } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->params_args || []
MC/DC0%0/1
$self->params_args || []
$self->params_args
Truth table50%1/2
A
A= $self->params_args
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 1 | my $new_params = $_fix_params->expand_hash($params); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 1 | return $new_params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 4 | ▶ | sub add_form_error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_form_error: called CC=2 SCAR=7.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 4 | my ( $self, @message ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 4 | ▶ | unless ( defined $message[0] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | @message = ('form is invalid'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 4 | my $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 4 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 4 | $out = $self->_localize(@message); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | die "Error occurred localizing error message for " . $self->name . ". $_"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 4 | $self->push_form_errors($out); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 324 | ▶ | sub get_default_value { } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_default_value: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | ▶ | sub _can_deflate { } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_can_deflate: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 295 | ▶ | sub update_fields { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_fields: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 295 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 295 | ▶ | if( $self->has_update_field_list ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 4 | my $updates = $self->update_field_list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 4 | foreach my $field_name ( keys %{$updates} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 6 | $self->update_field($field_name, $updates->{$field_name} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 4 | $self->clear_update_field_list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 295 | ▶ | if( $self->has_defaults ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 2 | my $defaults = $self->defaults; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 2 | foreach my $field_name ( keys %{$defaults} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 5 | $self->update_field($field_name, { default => $defaults->{$field_name} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 2 | $self->clear_defaults; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 11 | ▶ | sub update_field { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_field: called CC=5 SCAR=16.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 11 | my ( $self, $field_name, $updates ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 11 | my $field = $self->field($field_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 11 | ▶ | unless( $field ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | die "Field $field_name is not found and cannot be updated by update_fields"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 11 | ▶ | while ( my ( $attr_name, $attr_value ) = each %{$updates} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 13 | ▶ | confess "invalid attribute '$attr_name' passed to update_field" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | unless $field->can($attr_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 13 | ▶ | if( $attr_name eq 'tags' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 1 | $field->set_tag(%$attr_value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 12 | $field->$attr_name($attr_value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 147 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 147 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 147 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||