Plugin/Input.pm

filter: Statementstmt 100% 35 / 35 Branchbran 100% 6 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 5 / 5 totaltotal 96.7% 60 / 62 CC 6 SCAR 7.5
CC
6
Cov
98%
rewrite_arg
4.0
build
3.0
BEGIN
1.0
CRAP 2.1
« Plugin/Textarea.pm ↑ Summary Plugin/Password.pm »
1 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package HTML::Widget::Plugin::Input;
4 # ABSTRACT: the most basic input widget
5 15 $HTML::Widget::Plugin::Input::VERSION = '0.204';
6 15 ▶use parent 'HTML::Widget::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 #pod =head1 SYNOPSIS
9 #pod
10 #pod $widget_factory->input({
11 #pod id => 'flavor', # if "name" isn't given, id will be used for name
12 #pod size => 25,
13 #pod value => $default_flavor,
14 #pod });
15 #pod
16 #pod ...or...
17 #pod
18 #pod $widget_factory->hidden({
19 #pod id => 'flavor', # if "name" isn't given, id will be used for name
20 #pod value => $default_flavor,
21 #pod });
22 #pod
23 #pod =head1 DESCRIPTION
24 #pod
25 #pod This plugin provides a basic input widget.
26 #pod
27 #pod The C<default_classes> attribute may be used to add a default class to every
28 #pod produced input. This class cannot be overridden.
29 #pod
30 #pod my $plugin = HTML::Widget::Factory::Input->new({
31 #pod default_classes => [ qw(foo bar) ],
32 #pod });
33 #pod
34 #pod =cut
35  
36 15 ▶use HTML::Element;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 #pod =head1 METHODS
39 #pod
40 #pod =head2 C< provided_widgets >
41 #pod
42 #pod This plugin provides the following widgets: input, hidden
43 #pod
44 #pod =cut
45  
46 19 ▶sub provided_widgets { qw(input hidden) }
Subroutine provided_widgets: called CC=1 SCAR=0.0
Pod documented
47  
48 #pod =head2 C< input >
49 #pod
50 #pod This method returns a basic one-line text-entry widget.
51 #pod
52 #pod In addition to the generic L<HTML::Widget::Plugin> attributes, the following
53 #pod are valid arguments:
54 #pod
55 #pod =over
56 #pod
57 #pod =item value
58 #pod
59 #pod This is the widget's initial value.
60 #pod
61 #pod =item type
62 #pod
63 #pod This is the type of input widget to be created. You may wish to use a
64 #pod different plugin, instead.
65 #pod
66 #pod =back
67 #pod
68 #pod =cut
69  
70 84 ▶sub _attribute_args { qw(disabled type value size maxlength) }
Subroutine _attribute_args: called CC=1 SCAR=0.0
71 135 ▶sub _boolean_args { qw(disabled) }
Subroutine _boolean_args: called CC=1 SCAR=0.0
72  
73 8 ▶sub input {
Subroutine input: called CC=1 SCAR=0.0
Pod documented
74 8 my ($self, $factory, $arg) = @_;
75  
76 8 $self->build($factory, $arg);
77 }
78  
79 #pod =head2 C< hidden >
80 #pod
81 #pod This method returns a hidden input that is not displayed in the rendered HTML.
82 #pod Its arguments are the same as those to C<input>.
83 #pod
84 #pod This method may later be factored out into a plugin.
85 #pod
86 #pod =cut
87  
88 1 ▶sub hidden {
Subroutine hidden: called CC=1 SCAR=0.0
Pod documented
89 1 my ($self, $factory, $arg) = @_;
90  
91 1 $arg->{attr}{type} = 'hidden';
92  
93 1 $self->build($factory, $arg);
94 }
95  
96 #pod =head2 C< build >
97 #pod
98 #pod my $widget = $class->build($factory, $arg);
99 #pod
100 #pod This method does the actual construction of the input based on the args
101 #pod collected by the widget-constructing method. It is primarily here for
102 #pod subclasses to exploit.
103 #pod
104 #pod =cut
105  
106 11 ▶sub build {
Subroutine build: called CC=3 SCAR=11.0
Pod documented
107 11 my ($self, $factory, $arg) = @_;
108  
109 11 ▶ $arg->{attr}{name} = $arg->{attr}{id} unless defined $arg->{attr}{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg->{"attr"}{"name"} 5 6 11
110  
111 11 my $widget = HTML::Element->new('input');
112  
113 11 $widget->attr($_ => $arg->{attr}{$_}) for keys %{ $arg->{attr} };
114 11 return $widget->as_XML;
115 }
116  
117 11 ▶sub rewrite_arg {
Subroutine rewrite_arg: called CC=4 SCAR=13.9
Pod documented
118 11 my ($self, $arg, $method) = @_;
119  
120 11 $arg = $self->SUPER::rewrite_arg($arg);
121  
122 11 ▶ if ($self->{default_classes} && $method ne 'hidden') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"default_classes"} and $method ne "hidden") 2 9 11
Condition66%2/3
$self->{"default_classes"} and $method ne "hidden"
!ll&&!rl&&r
902
MC/DC50%1/2
$self->{"default_classes"} and $method ne "hidden"
$self->{"default_classes"} $method ne "hidden"
Truth table66%2/3
A and B
A= $self->{"default_classes"}B= $method ne "hidden"
ABresult
0X0
100
111
123 2 my $class = join q{ }, @{ $self->{default_classes} };
124 $arg->{attr}{class} = defined $arg->{attr}{class}
125 2 ▶ ? "$class $arg->{attr}{class}"
Branch: 1 branch
BranchTrueFalseTotal
defined $arg->{'attr'}{'class'} ? : 1 1 2
126 : $class;
127 }
128  
129 11 return $arg;
130 }
131  
132  
133 15 1;
134  
135 __END__
« Plugin/Textarea.pm ↑ Summary Plugin/Password.pm »