FormHandler/Wizard.pm

filter: Statementstmt 98.3% 58 / 59 Branchbran 75.0% 12 / 16 Conditioncond 75.0% 6 / 8 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 10 / 10 Podpod 14.2% 1 / 7 totaltotal 84.6% 88 / 104 CC 15 SCAR 14.1
CC
15
Cov
92%
set_active
7.3
__ANON__
5.0
build_active
3.0
CRAP 4.1
« FormHandler/Field/Password.pm ↑ Summary FormHandler/Result/Role.pm »
1 package HTML::FormHandler::Wizard;
2 # ABSTRACT: create a multi-page form
3 1 $HTML::FormHandler::Wizard::VERSION = '0.410002';
4 1 ▶use HTML::FormHandler::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 extends 'HTML::FormHandler';
6 1 with ('HTML::FormHandler::BuildPages', 'HTML::FormHandler::Pages' );
7  
8  
9 2 ▶sub is_wizard {1}
Subroutine is_wizard: called CC=1 SCAR=0.0
Pod undocumented
10  
11 1 has_field 'page_num' => ( type => 'Hidden', default => 1 );
12  
13 1 has 'on_last_page' => ( is => 'rw', isa => 'Bool', default => 0 );
14 1 has 'stash' => ( is => 'rw', isa => 'HashRef' );
15 1 has 'save_to' => ( is => 'rw', isa => 'Str' ); # 'item', 'stash', 'temp_table'
16  
17 # temp_table: DBIC row or other object with three columns:
18 # form, field, value
19 #
20 1 has 'temp_table' => ( is => 'rw' );
21  
22 16 ▶sub validated {
Subroutine validated: called CC=2 SCAR=7.1
Pod documented
23 16 my $self = shift;
24 16 ▶ return $self->next::method && $self->on_last_page;
Condition66%2/3
$self->next::method && $self->on_last_page
!ll&&!rl&&r
907
MC/DC50%1/2
$self->next::method && $self->on_last_page
$self->next::method $self->on_last_page
Truth table66%2/3
A && B
A= $self->next::methodB= $self->on_last_page
ABresult
0X0
100
111
25 }
26  
27 3 ▶sub page_validated {
Subroutine page_validated: called CC=1 SCAR=0.0
Pod undocumented
28 3 my $self = shift;
29 3 return $self->SUPER::validated;
30 }
31  
32 2 ▶sub build_active {
Subroutine build_active: called CC=3 SCAR=11.0
Pod undocumented
33 2 my $self = shift;
34  
35 2 my @page_fields;
36 2 foreach my $page ( $self->all_pages ) {
37 6 push @page_fields, $page->all_fields;
38 }
39 2 foreach my $field_name ( @page_fields ) {
40 6 $self->field($field_name)->inactive(1);
41 }
42 }
43  
44  
45 6 ▶sub set_active {
Subroutine set_active: called CC=7 SCAR=19.9
Pod undocumented
46 6 my ( $self, $current_page ) = @_;;
47  
48 6 ▶ $current_page ||= $self->get_param('page_num') || 1;
Condition80%4/5
$current_page ||= $self->get_param("page_num") || 1
l!l&&r!l&&!r
240
$self->get_param('page_num') || 1
l!l
31
MC/DC0%0/2
$current_page ||= $self->get_param("page_num") || 1
$current_page $self->get_param('page_num')
Truth table66%2/3
A ||= B
A= $current_pageB= $self->get_param('page_num')
ABresult
1X1
011
000
49 6 ▶ return if $current_page > $self->num_pages;
Branch: 1 branch
BranchTrueFalseTotal
if $current_page > $self->num_pages 0 6 6
50 6 ▶ $self->on_last_page(1) if $current_page == $self->num_pages;
Branch: 1 branch
BranchTrueFalseTotal
if $current_page == $self->num_pages 2 4 6
51 6 my $page = $self->get_page( $current_page - 1 );
52  
53 6 foreach my $fname ( $page->all_fields ) {
54 6 my $field = $self->field($fname);
55 6 ▶ if ( $field ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field) { } 6 0 6
56 6 $field->_active(1);
57 }
58 else {
59 0 warn "field $fname not found for page " . $page->name;
60 }
61 }
62 }
63  
64 3 ▶after 'validate_form' => sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
65 3 my $self = shift;
66 3 ▶ if( $self->page_validated ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->page_validated) 3 0 3
67 3 $self->save_page;
68 3 ▶ if( $self->field('page_num')->value < $self->num_pages ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->field('page_num')->value < $self->num_pages) { } 2 1 3
elsif ($self->field('page_num')->value == $self->num_pages) { } 1 0 1
69 2 my $new_page_num = $self->field('page_num')->value + 1;
70 2 $self->clear_page;
71 2 $self->set_active( $new_page_num );
72 2 $self->_result_from_fields( $self->result );
73 2 $self->field('page_num')->value($new_page_num);
74 2 ▶ $self->on_last_page(1) if $new_page_num == $self->num_pages;
Branch: 1 branch
BranchTrueFalseTotal
if $new_page_num == $self->num_pages 1 1 2
75 }
76 elsif( $self->field('page_num')->value == $self->num_pages ) {
77 1 $self->_set_value( $self->stash );
78 }
79 }
80 1 };
81  
82 2 ▶sub clear_page {
Subroutine clear_page: called CC=1 SCAR=0.0
Pod undocumented
83 2 my $self = shift;
84 2 $self->clear_data;
85 2 $self->clear_params;
86 2 $self->processed(0);
87 # $self->did_init_obj(0);
88 2 $self->clear_result;
89 }
90  
91 3 ▶sub save_page {
Subroutine save_page: called CC=2 SCAR=6.9
Pod undocumented
92 3 my $self = shift;
93  
94 3 my $stash = $self->stash;
95 3 ▶ while ( my ($key, $value) = each %{$self->value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$self->value;}) 6 3 9
96 6 $stash->{$key} = $value;
97 }
98 }
99  
100 1 __PACKAGE__->meta->make_immutable;
101 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
102 1 1;
103  
104 __END__
« FormHandler/Field/Password.pm ↑ Summary FormHandler/Result/Role.pm »