| 1 | package Rose::HTML::Form::Repeatable; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 2 | ▶ | use Rose::HTML::Form; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 2 | ▶ | use base 'Rose::HTML::Object::Repeatable'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 2 | our $VERSION = '0.616'; | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 2 | __PACKAGE__->default_form_class('Rose::HTML::Form'); | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | # | ||||||||||||||||||||
| 14 | # Class methods | ||||||||||||||||||||
| 15 | # | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 2 | ▶ | sub default_form_class { shift->default_prototype_class(@_) } | ||||||||||||||||||
|
Subroutine
default_form_class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | # | ||||||||||||||||||||
| 20 | # Object methods | ||||||||||||||||||||
| 21 | # | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 9 | ▶ | sub prototype_form { shift->prototype(@_) } | ||||||||||||||||||
|
Subroutine
prototype_form: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 24 | 3 | ▶ | sub prototype_form_spec { shift->prototype_spec(@_) } | ||||||||||||||||||
|
Subroutine
prototype_form_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 25 | 4 | ▶ | sub prototype_form_class { shift->prototype_class(@_) } | ||||||||||||||||||
|
Subroutine
prototype_form_class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 26 | 32 | ▶ | sub prototype_form_clone { shift->prototype_clone(@_) } | ||||||||||||||||||
|
Subroutine
prototype_form_clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 0 | ▶ | sub form_class { shift->prototype_form_class(@_) } | ||||||||||||||||||
|
Subroutine
form_class: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 4 | ▶ | sub is_repeatable_form { 1 } | ||||||||||||||||||
|
Subroutine
is_repeatable_form: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | sub prepare | ||||||||||||||||||||
| 33 | 33 | ▶ | { | ||||||||||||||||||
|
Subroutine
prepare: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||
| 34 | 33 | my($self) = shift; | |||||||||||||||||||
| 35 | 33 | my(%args) = @_; | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 33 | my $fq_form_name = quotemeta $self->fq_form_name; | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 33 | my $re = qr(^$fq_form_name\.(\d+)\.); | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 33 | my %have_num; | |||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 33 | foreach my $param (keys %{$self->params}) | |||||||||||||||||||
| 44 | { | ||||||||||||||||||||
| 45 | 134 | ▶ | if($param =~ $re) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | { | ||||||||||||||||||||
| 47 | 75 | my $num = $1; | |||||||||||||||||||
| 48 | 75 | $have_num{$num}++; | |||||||||||||||||||
| 49 | 75 | ▶ | my $form = $self->form($num) || $self->make_form($num); | ||||||||||||||||||
|
Condition66%2/3
$self->form($num) || $self->make_form($num)
MC/DC0%0/2
$self->form($num) || $self->make_form($num)
$self->form($num)
$self->make_form($num)
Truth table66%2/3
A || B
A= $self->form($num)B= $self->make_form($num)
| |||||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 33 | ▶ | unless(%have_num) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | { | ||||||||||||||||||||
| 55 | 9 | ▶ | if($self->default_count) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | { | ||||||||||||||||||||
| 57 | 8 | foreach my $num (1 .. $self->default_count) | |||||||||||||||||||
| 58 | { | ||||||||||||||||||||
| 59 | 14 | ▶ | $self->form($num) || $self->make_form($num); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 14 | $have_num{$num}++; | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | else | ||||||||||||||||||||
| 64 | { | ||||||||||||||||||||
| 65 | 1 | $self->delete_forms; | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 33 | ▶ | if(%have_num) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | { | ||||||||||||||||||||
| 71 | 32 | foreach my $form ($self->forms) | |||||||||||||||||||
| 72 | { | ||||||||||||||||||||
| 73 | 73 | ▶ | unless($have_num{$form->form_name}) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | { | ||||||||||||||||||||
| 75 | 11 | $self->delete_form($form->form_name); | |||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 33 | ▶ | $self->SUPER::prepare(@_) unless(delete $args{'init_only'}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | sub init_fields | ||||||||||||||||||||
| 84 | 28 | ▶ | { | ||||||||||||||||||
|
Subroutine
init_fields: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 85 | 28 | my($self) = shift; | |||||||||||||||||||
| 86 | 28 | $self->prepare(init_only => 1); | |||||||||||||||||||
| 87 | 28 | $self->SUPER::init_fields(@_); | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | sub make_form | ||||||||||||||||||||
| 91 | 31 | ▶ | { | ||||||||||||||||||
|
Subroutine
make_form: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||
| 92 | 31 | my($self, $num) = @_; | |||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 31 | ▶ | Carp::croak "Missing form nubmer argument" unless(@_ > 1); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 95 | 31 | ▶ | Carp::croak "Form number argument must be greater than 0" unless($num > 0); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 31 | my $form = $self->prototype_form_clone; | |||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 31 | $form->rank($num); | |||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 31 | ▶ | $self->form_rank_counter($num + 1) if($num >= $self->form_rank_counter); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 31 | $form->prepare; | |||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 31 | $self->add_form($num => $form); | |||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | 31 | return $form; | |||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | sub make_next_form | ||||||||||||||||||||
| 111 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
make_next_form: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 112 | 3 | my ($self) = shift; | |||||||||||||||||||
| 113 | 3 | $self->increment_form_rank_counter; # XXX: Remove when form_rank_counter is removed | |||||||||||||||||||
| 114 | 3 | return $self->make_form($self->next_form_rank); | |||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | sub objects_from_form | ||||||||||||||||||||
| 118 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
objects_from_form: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 119 | 0 | my($self) = shift; | |||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | 0 | my $method = 'object_from_form'; | |||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 0 | ▶ | if(@_ > 1) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 124 | { | ||||||||||||||||||||
| 125 | 0 | my %args = @_; | |||||||||||||||||||
| 126 | 0 | ▶ | $method = $args{'method'} if($args{'method'}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | 0 | my @objects = map { $_->$method(@_) } $self->forms; | |||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | 0 | ▶ | return wantarray ? @objects : \@objects; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 132 | } | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | sub init_with_objects | ||||||||||||||||||||
| 135 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
init_with_objects: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 136 | 0 | my($self) = shift; | |||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | 0 | my $method = 'init_with_object'; | |||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | 0 | my $objects; | |||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | 0 | ▶ | if(@_ > 1) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 143 | { | ||||||||||||||||||||
| 144 | 0 | my %args = @_; | |||||||||||||||||||
| 145 | 0 | ▶ | $method = $args{'method'} if($args{'method'}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 146 | 0 | $objects = $args{'objects'}; | |||||||||||||||||||
| 147 | } | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | 0 | ▶ | unless($objects) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 150 | { | ||||||||||||||||||||
| 151 | 0 | $objects = \@_; | |||||||||||||||||||
| 152 | } | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | 0 | foreach my $form ($self->forms) | |||||||||||||||||||
| 155 | { | ||||||||||||||||||||
| 156 | 0 | $form->$method(shift(@$objects)); | |||||||||||||||||||
| 157 | } | ||||||||||||||||||||
| 158 | } | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | 2 | 1; | |||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | __END__ | ||||||||||||||||||||