| 1 | package HTML::FormHandler::Field::IntRange; | ||||||||||||
| 2 | # ABSTRACT: integer range in select list | ||||||||||||
| 3 | 3 | $HTML::FormHandler::Field::IntRange::VERSION = '0.410000'; | |||||||||||
| 4 | 3 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 3 | extends 'HTML::FormHandler::Field::Select'; | |||||||||||
| 6 | |||||||||||||
| 7 | 3 | has 'label_format' => ( isa => 'Str', is => 'rw', default => '%d' ); | |||||||||||
| 8 | 3 | has '+range_start' => ( default => 1 ); | |||||||||||
| 9 | 3 | has '+range_end' => ( default => 10 ); | |||||||||||
| 10 | |||||||||||||
| 11 | sub build_options { | ||||||||||||
| 12 | 10 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
build_options: called CC=6 SCAR=18.6
Pod
undocumented
| |||||||||||||
| 13 | |||||||||||||
| 14 | 10 | my $start = $self->range_start; | |||||||||||
| 15 | 10 | my $end = $self->range_end; | |||||||||||
| 16 | |||||||||||||
| 17 | 10 | for ( $start, $end ) { | |||||||||||
| 18 | 20 | ▶ | die "Both range_start and range_end must be defined" unless defined $_; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 19 | 20 | ▶ | die "Integer ranges must be integers" unless /^\d+$/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 20 | } | ||||||||||||
| 21 | |||||||||||||
| 22 | 10 | ▶ | die "range_start must be less than range_end" unless $start < $end; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 23 | |||||||||||||
| 24 | 10 | ▶ | my $format = $self->label_format || die 'IntRange needs label_format'; | ||||||||||
|
Condition50%1/2
$self->label_format || die('IntRange needs label_format')
MC/DC0%0/1
$self->label_format || die('IntRange needs label_format')
$self->label_format
Truth table50%1/2
A
A= $self->label_format
| |||||||||||||
| 25 | |||||||||||||
| 26 | 10 | return [ map { { value => $_, label => sprintf( $format, $_ ) } } | |||||||||||
| 27 | $self->range_start .. $self->range_end ]; | ||||||||||||
| 28 | } | ||||||||||||
| 29 | |||||||||||||
| 30 | |||||||||||||
| 31 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 32 | 3 | ▶ | use namespace::autoclean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 33 | 3 | 1; | |||||||||||
| 34 | |||||||||||||
| 35 | __END__ | ||||||||||||
| 36 | |||||||||||||
| 37 | =pod | ||||||||||||
| 38 | |||||||||||||
| 39 | =encoding UTF-8 | ||||||||||||
| 40 | |||||||||||||
| 41 | =head1 NAME | ||||||||||||
| 42 | |||||||||||||
| 43 | HTML::FormHandler::Field::IntRange - integer range in select list | ||||||||||||
| 44 | |||||||||||||
| 45 | =head1 VERSION | ||||||||||||
| 46 | |||||||||||||
| 47 | version 0.410000 | ||||||||||||
| 48 | |||||||||||||
| 49 | =head1 DESCRIPTION | ||||||||||||
| 50 | |||||||||||||
| 51 | This field generates a select list of numbers from 1 to 10. Override the | ||||||||||||
| 52 | range_start and range_end for a select list with a different range. | ||||||||||||
| 53 | |||||||||||||
| 54 | has_field 'age' => ( type => 'IntRange', | ||||||||||||
| 55 | range_start => 0, range_end => 100 ); | ||||||||||||
| 56 | |||||||||||||
| 57 | Widget type is 'select'. | ||||||||||||
| 58 | |||||||||||||
| 59 | =head1 AUTHOR | ||||||||||||
| 60 | |||||||||||||
| 61 | FormHandler Contributors - see HTML::FormHandler | ||||||||||||
| 62 | |||||||||||||
| 63 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 64 | |||||||||||||
| 65 | This software is copyright (c) 2017 by Gerda Shank. | ||||||||||||
| 66 | |||||||||||||
| 67 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 68 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 69 | |||||||||||||
| 70 | =cut | ||||||||||||