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.410000';
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 sub validated {
23 16 ▶ my $self = shift;
Subroutine validated: called CC=2 SCAR=7.1
Pod documented
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 sub page_validated {
28 3 ▶ my $self = shift;
Subroutine page_validated: called CC=1 SCAR=0.0
Pod undocumented
29 3 return $self->SUPER::validated;
30 }
31  
32 sub build_active {
33 2 ▶ my $self = shift;
Subroutine build_active: called CC=3 SCAR=11.0
Pod undocumented
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 sub set_active {
46 6 ▶ my ( $self, $current_page ) = @_;;
Subroutine set_active: called CC=7 SCAR=19.9
Pod undocumented
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 after 'validate_form' => sub {
65 3 ▶ my $self = shift;
Subroutine __ANON__: called CC=5 SCAR=16.2
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 sub clear_page {
83 2 ▶ my $self = shift;
Subroutine clear_page: called CC=1 SCAR=0.0
Pod undocumented
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 sub save_page {
92 3 ▶ my $self = shift;
Subroutine save_page: called CC=2 SCAR=6.9
Pod undocumented
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__
105  
106 =pod
107  
108 =encoding UTF-8
109  
110 =head1 NAME
111  
112 HTML::FormHandler::Wizard - create a multi-page form
113  
114 =head1 VERSION
115  
116 version 0.410000
117  
118 =head1 SYNOPSIS
119  
120 This feature is EXPERIMENTAL. That means that the interface may change,
121 and that it hasn't been fully implemented.
122 We are actively looking for input, so if you are interested in this
123 feature, please show up on the FormHandler mailing list or irc channel
124 (#formhandler on irc.perl.org) to discuss.
125  
126 package Test::Wizard;
127 use HTML::FormHandler::Moose;
128 extends 'HTML::FormHandler::Wizard';
129  
130 has_field 'foo';
131 has_field 'bar';
132 has_field 'zed';
133  
134 has_page 'one' => ( fields => ['foo'] );
135 has_page 'two' => ( fields => ['bar'] );
136 has_page 'three' => ( fields => ['zed'] );
137  
138 ...
139  
140 my $stash = {};
141 my $wizard = Test::Wizard->new( stash => $stash );
142 $wizard->process( params => $params );
143  
144 =head1 AUTHOR
145  
146 FormHandler Contributors - see HTML::FormHandler
147  
148 =head1 COPYRIGHT AND LICENSE
149  
150 This software is copyright (c) 2017 by Gerda Shank.
151  
152 This is free software; you can redistribute it and/or modify it under
153 the same terms as the Perl 5 programming language system itself.
154  
155 =cut
« FormHandler/Field/Password.pm ↑ Summary FormHandler/Result/Role.pm »