| 1 |
package HTML::FormHandler::Pages; |
| 2 |
# ABSTRACT: used in Wizard |
| 3 |
$HTML::FormHandler::Pages::VERSION = '0.410002'; |
| 4 |
use Moose::Role; |
| 5 |
|
| 6 |
has 'pages' => ( |
| 7 |
traits => ['Array'], |
| 8 |
isa => 'ArrayRef[HTML::FormHandler::Page]', |
| 9 |
is => 'rw', |
| 10 |
default => sub { [] }, |
| 11 |
auto_deref => 1, |
| 12 |
handles => { |
| 13 |
all_pages => 'elements', |
| 14 |
clear_pages => 'clear', |
| 15 |
push_page => 'push', |
| 16 |
num_pages => 'count', |
| 17 |
has_pages => 'count', |
| 18 |
set_page_at => 'set', |
| 19 |
get_page => 'get', |
| 20 |
} |
| 21 |
); |
| 22 |
|
| 23 |
has 'page_name_space' => ( |
| 24 |
isa => 'Str|ArrayRef[Str]|Undef', |
| 25 |
is => 'rw', |
| 26 |
lazy => 1, |
| 27 |
builder => 'build_page_name_space', |
| 28 |
); |
| 29 |
|
| 30 |
sub build_page_name_space { '' } |
| 31 |
|
| 32 |
sub page_index { |
| 33 |
my ( $self, $name ) = @_; |
| 34 |
my $index = 0; |
| 35 |
for my $page ( $self->all_pages ) { |
| 36 |
return $index if $page->name eq $name; |
| 37 |
$index++; |
| 38 |
} |
| 39 |
return; |
| 40 |
} |
| 41 |
|
| 42 |
sub page { |
| 43 |
my ( $self, $name, $die ) = @_; |
| 44 |
|
| 45 |
my $index; |
| 46 |
# if this is a full_name for a compound page |
| 47 |
# walk through the pages to get to it |
| 48 |
return undef unless ( defined $name ); |
| 49 |
if ( $name =~ /\./ ) { |
| 50 |
my @names = split /\./, $name; |
| 51 |
my $f = $self->form || $self; |
| 52 |
foreach my $pname (@names) { |
| 53 |
$f = $f->page($pname); |
| 54 |
return unless $f; |
| 55 |
} |
| 56 |
return $f; |
| 57 |
} |
| 58 |
else # not a compound name |
| 59 |
{ |
| 60 |
for my $page ( $self->all_pages ) { |
| 61 |
return $page if ( $page->name eq $name ); |
| 62 |
} |
| 63 |
} |
| 64 |
return unless $die; |
| 65 |
die "Page '$name' not found in '$self'"; |
| 66 |
} |
| 67 |
|
| 68 |
1; |
| 69 |
|
| 70 |
__END__ |
| 71 |
|
| 72 |
=pod |
| 73 |
|
| 74 |
=encoding UTF-8 |
| 75 |
|
| 76 |
=head1 NAME |
| 77 |
|
| 78 |
HTML::FormHandler::Pages - used in Wizard |
| 79 |
|
| 80 |
=head1 VERSION |
| 81 |
|
| 82 |
version 0.410002 |
| 83 |
|
| 84 |
=head1 AUTHOR |
| 85 |
|
| 86 |
FormHandler Contributors - see HTML::FormHandler |
| 87 |
|
| 88 |
=head1 COPYRIGHT AND LICENSE |
| 89 |
|
| 90 |
This software is copyright (c) 2017 by Gerda Shank. |
| 91 |
|
| 92 |
This is free software; you can redistribute it and/or modify it under |
| 93 |
the same terms as the Perl 5 programming language system itself. |
| 94 |
|
| 95 |
=cut |