blib/lib/HTML/Shakan/Field/Choice.pm

filter: Statementstmt 100% 26 / 26 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 100% 33 / 33 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/HTML/Shakan/Filter/HTMLScrubber.pm ↑ Summary blib/lib/HTML/Shakan/Field/Date.pm »
1 package HTML::Shakan::Field::Choice;
2 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 22 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 22 ▶use List::Util qw/pairmap/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 22 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 22 extends 'HTML::Shakan::Field';
9  
10 22 has '+widget' => (
11 default => 'select'
12 );
13  
14 22 has choices => (
15 is => 'ro',
16 isa => 'ArrayRef',
17 required => 1,
18 );
19  
20 22 has 'id_tmpl' => (
21 is => 'ro',
22 isa => 'Str',
23 default => 'id_%s_%s',
24 );
25  
26 override 'get_constraints' => sub {
27 13 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
28 13 my ($name, $constraints) = super();
29  
30 return (
31 $name => [
32 @$constraints,
33 13 ▶ ['CHOICE' => [ pairmap { $a } @{$self->choices} ] ]
Subroutine __ANON__: called CC=1 SCAR=0.0
34 ]
35 );
36 22 };
37  
38 22 ▶no Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 22 __PACKAGE__->meta->make_immutable;
40 __END__
41  
42 =head1 NAME
43  
44 HTML::Shakan::Field::Choice - choice field
45  
46 =head1 SYNOPSIS
47  
48 use HTML::Shakan::Field::Choice;
49 HTML::Shakan::Field::Choice->new(
50 name => 'pref',
51 choices => [
52 #value=> label
53 tokyo => 'tokyo',
54 osaka => 'osaka',
55 kyoto => 'kyoto',
56 ],
57 );
58  
59 # or shortcut
60 use HTML::Shakan::Fields;
61 ChoiceField(
62 name => 'pref',
63 choices => [
64 tokyo => 'tokyo',
65 osaka => 'osaka',
66 kyoto => 'kyoto',
67 ],
68 );
69  
70 # if you want radio button
71 ChoiceField(
72 name => 'pref',
73 choices => [
74 tokyo => 'tokyo',
75 osaka => 'osaka',
76 kyoto => 'kyoto',
77 ],
78 widget => 'radio',
79 );
80  
81 # if you want checkbox
82 ChoiceField(
83 name => 'pref',
84 choices => [
85 tokyo => 'tokyo',
86 osaka => 'osaka',
87 kyoto => 'kyoto',
88 ],
89 widget => 'checkbox',
90 );
91  
92 =head1 DESCRIPTION
93  
94 Choice field implementation. This field may show in HTML as C<< <select></select> >> tag.
95  
96 =head1 base class
97  
98 HTML::Shakan::Field
99  
100 =head1 SEE ALSO
101  
102 L<HTML::Shakan>
« blib/lib/HTML/Shakan/Filter/HTMLScrubber.pm ↑ Summary blib/lib/HTML/Shakan/Field/Date.pm »