| 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | ########################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Copyright (c) Nate Wiger http://nateware.com. All Rights Reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Please visit http://formbuilder.org for tutorials, support, and examples. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | ########################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # Note: Documentation has grown so massive it is now in FormBuilder.pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | package CGI::FormBuilder; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 10 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 10 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 10 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 10 | ▶ | use CGI::FormBuilder::Util; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 10 | ▶ | use CGI::FormBuilder::Field; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 10 | ▶ | use CGI::FormBuilder::Messages; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 10 | our $VERSION = '3.10'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 10 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # Default options for FormBuilder | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 10 | our %DEFAULT = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | sticky => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | method => 'get', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | submit => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | reset => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | header => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | body => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | text => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | table => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | tr => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | th => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | td => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | div => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | jsname => 'validate', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | jsprefix => 'fb_', # prefix for JS tags | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | sessionidname => '_sessionid', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | submittedname => '_submitted', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | pagename => '_page', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | template => '', # default template | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | debug => 0, # can be 1 or 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | javascript => 'auto', # 0, 1, or 'auto' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | cookies => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | cleanopts => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | render => 'render', # render sub name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | smartness => 1, # can be 1 or 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | selectname => 1, # include -select-? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | selectnum => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | stylesheet => 0, # use stylesheet stuff? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | styleclass => 'fb', # style class to use | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # For translating tag names (experimental) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | tagnames => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # I don't see any reason why these are variables | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | formname => '_form', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | submitname => '_submit', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | resetname => '_reset', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | bodyname => '_body', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | tabname => '_tab', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | rowname => '_row', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | labelname => '_label', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | fieldname => '_field', # equiv of <tmpl_var field-tag> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | buttonname => '_button', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | errorname => '_error', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | othername => '_other', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | growname => '_grow', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | statename => '_state', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | extraname => '_extra', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | dtd => <<'EOD', # modified from CGI.pm | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | <?xml version="1.0" encoding="{charset}"?> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | <!DOCTYPE html | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | <html xmlns="http://www.w3.org/1999/xhtml" lang="{lang}" xml:lang="{lang}"> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | EOD | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # Which options to rearrange from new() into field() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 10 | our %REARRANGE = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | options options | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | optgroups optgroups | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | labels label | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | validate validate | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | required required | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | selectname selectname | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | selectnum selectnum | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | sortopts sortopts | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | nameopts nameopts | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | cleanopts cleanopts | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | sticky sticky | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | disabled disabled | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | columns columns | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 10 | *redo = \&new; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 123 | ▶ | local $^W = 0; # -w sucks | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=48 SCAR=45.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 123 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # A single arg is a source; others are opt => val pairs | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 123 | my %opt; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 123 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | %opt = UNIVERSAL::isa($_[0], 'HASH') | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 3 | ▶ | ? %{ $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | : ( source => shift() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 120 | %opt = arghash(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # Pre-check for an external source | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 123 | ▶ | if (my $src = delete $opt{source}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # check for engine type | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 23 | my $mod; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | my $sopt; # opts returned from parsing | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 23 | my $ref = ref $src; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 23 | ▶ | unless ($ref) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # string filename; redo format (ala $self->{template}) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | $src = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | type => 'File', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | source => $src, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # pass catalyst class for \&validate refs | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | ($opt{c} && $opt{c}->action) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | ? (caller => $opt{c}->action->class) : () | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opt{"c"} and $opt{"c"}->action
MC/DC0%0/2
$opt{"c"} and $opt{"c"}->action
$opt{"c"}
$opt{"c"}->action
Truth table0%0/3
A and B
A= $opt{"c"}B= $opt{"c"}->action
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | $ref = 'HASH'; # tricky | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | debug 2, "rewrote 'source' option since found filename"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 23 | ▶ | debug 1, "creating form from source ", $ref || $src; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$ref || $src
MC/DC0%0/2
$ref || $src
$ref
$src
Truth table33%1/3
A || B
A= $refB= $src
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 23 | ▶ | if ($ref eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # grab module | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 23 | ▶ | $mod = delete $src->{type} || 'File'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $src->{'type'} || 'File'
MC/DC100%1/1
delete $src->{'type'} || 'File'
delete $src->{'type'}
Truth table100%2/2
A
A= delete $src->{'type'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # user can give 'Their::Complete::Module' or an 'IncludedTemplate' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 23 | ▶ | $mod = join '::', __PACKAGE__, 'Source', $mod unless $mod =~ /::/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 23 | debug 1, "loading $mod for 'source' option"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 23 | eval "require $mod"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 23 | ▶ | puke "Bad source module $mod: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 23 | my $sob = $mod->new(%$src); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 23 | $sopt = $sob->parse; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } elsif ($ref eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # subroutine wrapper | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $sopt = &{$src->{source}}($self); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } elsif (UNIVERSAL::can($src->{source}, 'parse')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # instantiated object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | $sopt = $src->{source}->parse($self); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } elsif ($ref) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | puke "Unsupported operand to 'template' option - must be \\%hash, \\&sub, or \$object w/ parse()"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # per-instance variables win | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 23 | ▶ | while (my($k,$v) = each %$sopt) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 135 | ▶ | $opt{$k} = $v unless exists $opt{$k}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 123 | ▶ | if (ref $self) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # cloned/original object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | debug 1, "rewriting existing FormBuilder object"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | ▶ | while (my($k,$v) = each %opt) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | $self->{$k} = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 122 | debug 1, "constructing new FormBuilder object"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # damn deep copy this is SO damn annoying | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 122 | ▶ | while (my($k,$v) = each %DEFAULT) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 5368 | ▶ | next if exists $opt{$k}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 5092 | ▶ | if (ref $v eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 838 | $opt{$k} = { %$v }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } elsif (ref $v eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | $opt{$k} = [ @$v ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 4254 | $opt{$k} = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 122 | $self = bless \%opt, $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # Create our CGI object if not present | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 123 | ▶ | unless (ref $self->{params}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 119 | require CGI; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 119 | $CGI::USE_PARAM_SEMICOLONS = 0; # fuck ; in urls | |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 119 | $self->{params} = CGI->new($self->{params}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # XXX not mod_perl safe | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 123 | ▶ | $CGI::FormBuilder::Util::DEBUG = $ENV{FORMBUILDER_DEBUG} || $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$ENV{'FORMBUILDER_DEBUG'} || $self->{'debug'}
MC/DC0%0/2
$ENV{'FORMBUILDER_DEBUG'} || $self->{'debug'}
$ENV{'FORMBUILDER_DEBUG'}
$self->{'debug'}
Truth table33%1/3
A || B
A= $ENV{'FORMBUILDER_DEBUG'}B= $self->{'debug'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # And a messages delegate if not existent | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # Handle 'auto' mode by trying to detect from request | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # Can't do this in ::Messages because it has no CGI knowledge | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 123 | ▶ | if (lc($self->{messages}) eq 'auto') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 2 | my $lang = $self->{messages}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # figure out the messages from our params object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | ▶ | if (UNIVERSAL::isa($self->{params}, 'CGI')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | $lang = $self->{params}->http('Accept-Language'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } elsif (UNIVERSAL::isa($self->{params}, 'Apache')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $lang = $self->{params}->headers_in->get('Accept-Language'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } elsif (UNIVERSAL::isa($self->{params}, 'Catalyst::Request')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | $lang = $self->{params}->headers->header('Accept-Language'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # last-ditch effort | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | $lang = $ENV{HTTP_ACCEPT_LANGUAGE} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | || $ENV{LC_MESSAGES} || $ENV{LC_ALL} || $ENV{LANG}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
$ENV{'HTTP_ACCEPT_LANGUAGE'} || $ENV{'LC_MESSAGES'} || $ENV{'LC_ALL'} || $ENV{'LANG'}
$ENV{"HTTP_ACCEPT_LANGUAGE"} or $ENV{"LC_MESSAGES"} or $ENV{"LC_ALL"}
$ENV{"HTTP_ACCEPT_LANGUAGE"} or $ENV{"LC_MESSAGES"}
MC/DC0%0/4
$ENV{'HTTP_ACCEPT_LANGUAGE'} || $ENV{'LC_MESSAGES'} || $ENV{'LC_ALL'} || $ENV{'LANG'}
$ENV{"HTTP_ACCEPT_LANGUAGE"}
$ENV{"LC_MESSAGES"}
$ENV{"LC_ALL"}
$ENV{'LANG'}
Truth table0%0/5
A or B or C || D
A= $ENV{"HTTP_ACCEPT_LANGUAGE"}B= $ENV{"LC_MESSAGES"}C= $ENV{"LC_ALL"}D= $ENV{'LANG'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 2 | ▶ | $lang ||= 'default'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$lang ||= "default"
MC/DC0%0/1
$lang ||= "default"
$lang
Truth table50%1/2
A
A= $lang
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 2 | $self->{messages} = CGI::FormBuilder::Messages->new(":$lang"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # ref or filename (::Messages will decode) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 121 | $self->{messages} = CGI::FormBuilder::Messages->new($self->{messages}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # Initialize form fields (probably a good idea) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 123 | ▶ | if ($self->{fields}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 107 | debug 1, "creating fields list"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # check to see if 'fields' is a hash or array ref | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 107 | my $ref = ref $self->{fields}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 107 | ▶ | if ($ref && $ref eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ref and $ref eq "HASH"
MC/DC100%2/2
$ref and $ref eq "HASH"
$ref
$ref eq "HASH"
Truth table100%3/3
A and B
A= $refB= $ref eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # with a hash ref, we setup keys/values | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 4 | debug 2, "got fields list from HASH"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 4 | ▶ | while(my($k,$v) = each %{$self->{fields}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 8 | $k = lc $k; # must lc to ignore case | |||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 8 | $self->{values}{$k} = [ autodata $v ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # reset main fields to field names | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 4 | $self->{fields} = [ sort keys %{$self->{fields}} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # rewrite fields to ensure format | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 103 | debug 2, "assuming fields list from ARRAY"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 103 | $self->{fields} = [ autodata $self->{fields} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 123 | ▶ | if (UNIVERSAL::isa($self->{validate}, 'Data::FormValidator')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | debug 2, "got a Data::FormValidator for validate"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # we're being a bit naughty and peeking inside the DFV object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $self->{required} = $self->{validate}{profiles}{fb}{required}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # Catch the intersection of required and validate | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 123 | ▶ | if (ref $self->{required}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # ok, will handle itself automatically below | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } elsif ($self->{required}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # catches for required => 'ALL'|'NONE' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 8 | ▶ | if ($self->{required} eq 'NONE') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1 | delete $self->{required}; # that's it | |||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | elsif ($self->{required} eq 'ALL') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 6 | $self->{required} = [ @{$self->{fields}} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | elsif ($self->{required}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # required => 'single_field' catch | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | $self->{required} = { $self->{required} => 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } elsif ($self->{validate}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # construct a required list of all validated fields | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 28 | $self->{required} = [ keys %{$self->{validate}} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # Now, new for the 3.x series, we cycle thru the fields list and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # replace it with a list of objects, which stringify to field names | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 123 | my @ftmp = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 123 | for (@{$self->{fields}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 298 | ▶ | my %fprop = %{$self->{fieldopts}{$_} || {}}; # field properties | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 298 | ▶ | if (ref $_ =~ /^CGI::FormBuilder::Field/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # is an existing Field object, so update its properties | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $_->field(%fprop); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # init a new one | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 298 | $fprop{name} = "$_"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 298 | $_ = $self->new_field(%fprop); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 298 | weaken($_->{_form}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 298 | debug 2, "push \@(@ftmp), $_"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 298 | weaken($self->{fieldrefs}{"$_"} = $_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 298 | push @ftmp, $_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # stringifiable objects (overwrite previous container) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 123 | $self->{fields} = \@ftmp; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | # setup values | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 123 | ▶ | $self->values($self->{values}) if $self->{values}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 123 | debug 1, "field creation done, list = (@ftmp)"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 123 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 10 | *param = \&field; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 10 | *params = \&field; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 10 | *fields = \&field; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | sub field { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 1096 | ▶ | local $^W = 0; # -w sucks | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
field: called CC=16 SCAR=35.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 1096 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 1096 | debug 2, "called \$form->field(@_)"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # Handle any of: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # $form->field($name) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | # $form->field(name => $name, arg => 'val') | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | # $form->field(\@newlist); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 1096 | ▶ | return $self->new(fields => $_[0]) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $_[0] eq "ARRAY" and @_ == 1
MC/DC50%1/2
ref $_[0] eq "ARRAY" and @_ == 1
ref $_[0] eq "ARRAY"
@_ == 1
Truth table66%2/3
A and B
A= ref $_[0] eq "ARRAY"B= @_ == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | if ref $_[0] eq 'ARRAY' && @_ == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 1095 | ▶ | my $name = (@_ % 2 == 0) ? '' : shift(); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1095 | my $args = arghash(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 1095 | ▶ | $args->{name} ||= $name; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$args->{"name"} ||= $name
MC/DC100%2/2
$args->{"name"} ||= $name
$args->{"name"}
$name
Truth table100%3/3
A ||= B
A= $args->{"name"}B= $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # no name - return ala $cgi->param | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 1095 | ▶ | unless ($args->{name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | # sub fields | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | # return an array of the names in list context, and a | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | # hashref of name/value pairs in a scalar context | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 953 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | # pre-scan for any "order" arguments, reorder, delete | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 952 | for my $redo (grep { $_->order } @{$self->{fields}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | next if $redo->order eq 'auto'; # like javascript | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | # kill existing order | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | for (my $i=0; $i < @{$self->{fields}}; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | if ($self->{fields}[$i] eq $redo) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | debug 2, "reorder: removed $redo from \$fields->[$i]"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | splice(@{$self->{fields}}, $i, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # put it in its new place | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | debug 2, "reorder: moving $redo to $redo->{order}"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | if ($redo->order <= 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | # start | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | unshift @{$self->{fields}}, $redo; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | } elsif ($redo->order >= @{$self->{fields}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | # end | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | push @{$self->{fields}}, $redo; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | # middle | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | splice(@{$self->{fields}}, $redo->order - 1, 0, $redo); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | # kill subsequent reorders (unnecessary) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | delete $redo->{order}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | # list of all field objects | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 952 | debug 2, "return (@{$self->{fields}})"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 952 | return @{$self->{fields}}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | # this only returns a single scalar value for each field | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 1 | return { map { $_ => scalar($_->value) } @{$self->{fields}} }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | # have name, so redispatch to field member | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 142 | debug 2, "searching fields for '$args->{name}'"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 142 | ▶ | if ($args->{delete}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | # blow the thing away | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | delete $self->{fieldrefs}{$args->{name}}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | my @tf = grep { $_->name ne $args->{name} } @{$self->{fields}}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | $self->{fields} = \@tf; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } elsif (my $f = $self->{fieldrefs}{$args->{name}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 92 | delete $args->{name}; # segfault?? | |||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 92 | return $f->field(%$args); # set args, get value back | |||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | # non-existent field, and no args, so assume we're checking for it | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 50 | ▶ | return unless keys %$args > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | # if we're still in here, we need to init a new field | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | # push it onto our mail fields array, just like initfields() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 42 | my $f = $self->new_field(%$args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 42 | weaken($self->{fieldrefs}{"$f"} = $f); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 42 | weaken($f->{_form}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 42 | weaken($f->{fieldrefs}{"$f"}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 42 | push @{$self->{fields}}, $f; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 42 | return $f->value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | sub new_field { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 340 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_field: called CC=10 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 340 | my $args = arghash(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 340 | ▶ | puke "Need a name for \$form->new_field()" unless exists $args->{name}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 340 | debug 1, "called \$form->new_field($args->{name})"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | # extract our per-field options from rearrange | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 340 | ▶ | while (my($from,$to) = each %REARRANGE) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 4420 | ▶ | next unless exists $self->{$from}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 1725 | ▶ | next if defined $args->{$to}; # manually set | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 1721 | my $tval = rearrange($self->{$from}, $args->{name}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 1721 | debug 2, "rearrange: \$args->{$to} = $tval;"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 1721 | $args->{$to} = $tval; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | $args->{type} = lc $self->{fieldtype} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 340 | ▶ | if $self->{fieldtype} && ! exists $args->{type}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"fieldtype"} and not exists $args->{"type"}
MC/DC50%1/2
$self->{"fieldtype"} and not exists $args->{"type"}
$self->{"fieldtype"}
not exists $args->{"type"}
Truth table66%2/3
A and not(B)
A= $self->{"fieldtype"}B= not exists $args->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 340 | ▶ | if ($self->{fieldattr}) { # legacy | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 11 | ▶ | while (my($k,$v) = each %{$self->{fieldattr}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 11 | ▶ | next if exists $args->{$k}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 11 | $args->{$k} = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 340 | my $f = CGI::FormBuilder::Field->new($self, $args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 340 | debug 1, "created field $f"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 340 | return $f; # already set args above ^^^ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 10 | *fieldset = \&fieldsets; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | sub fieldsets { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 258 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fieldsets: called CC=15 SCAR=38.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 258 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | if (ref($_[0]) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | $self->{fieldsets} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } elsif (@_ % 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # search for fieldset and update it, or add it | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | # can't use optalign because must change in-place | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | my($k,$v) = (shift,shift); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | for (@{$self->{fieldsets}||=[]}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"fieldsets"} ||= []
MC/DC0%0/1
$self->{"fieldsets"} ||= []
$self->{"fieldsets"}
Truth table0%0/2
A
A= $self->{"fieldsets"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | ▶ | if ($k eq $_->[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | $_->[1] = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | undef $k; # catch below | |||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | # not found, so append | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | if ($k) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | push @{$self->{fieldsets}}, [$k,$v]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | puke "Invalid usage of \$form->fieldsets(name => 'Label')" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | # We look for all the fieldset definitions, checking the main | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | # form for a "proper" legend ala our other settings. We then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | # divide up all the fields and group them in fieldsets. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 258 | my(%legends, @sets); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 258 | for (optalign($self->{fieldsets})) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 270 | my($o,$n) = optval($_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 270 | ▶ | next if exists $legends{$o}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 270 | push @sets, $o; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 270 | debug 2, "added fieldset $o (legend=$n) to \@sets"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 270 | $legends{$o} = $n; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | # find *all* our fieldsets, even hidden in fields w/o Human Tags | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 258 | for ($self->field) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 748 | ▶ | next unless my $o = $_->fieldset; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 44 | ▶ | next if exists $legends{$o}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 4 | push @sets, $o; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 4 | debug 2, "added fieldset $o (legend=undef) to \@sets"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 4 | $legends{$o} = $o; # use fieldset as <legend> | |||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 258 | ▶ | return wantarray ? @sets : \%legends; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | sub fieldlist { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 59 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fieldlist: called CC=10 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 59 | ▶ | my @fields = @_ ? @_ : $self->field; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 59 | my(%saw, @ret); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 59 | for my $set ($self->fieldsets) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | # reorder fields | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 63 | for (@fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 213 | ▶ | next if $saw{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 194 | ▶ | if ($_->fieldset && $_->fieldset eq $set) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$_->fieldset and $_->fieldset eq $set
MC/DC100%2/2
$_->fieldset and $_->fieldset eq $set
$_->fieldset
$_->fieldset eq $set
Truth table100%3/3
A and B
A= $_->fieldsetB= $_->fieldset eq $set
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | # if this field is in this fieldset, regroup | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 11 | push @ret, $_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 11 | debug 2, "added field $_ to field order (fieldset=$set)"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 11 | $saw{$_} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | # keep non-fieldset fields in order relative | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | # to one another, appending them to the end | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | # of the form | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 59 | for (@fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 173 | debug 2, "appended non-fieldset field $_ to form"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 173 | ▶ | push @ret, $_ unless $saw{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 59 | ▶ | return wantarray ? @ret : \@ret; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | sub header { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 123 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
header: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 123 | ▶ | $self->{header} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 123 | ▶ | return unless $self->{header}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 29 | my %head; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 29 | ▶ | if ($self->{cookies} && defined(my $sid = $self->sessionid)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"cookies"} and defined(my $sid = $self->sessionid)
MC/DC50%1/2
$self->{"cookies"} and defined(my $sid = $self->sessionid)
$self->{"cookies"}
defined(my $sid = $self->sessionid)
Truth table66%2/3
A and B
A= $self->{"cookies"}B= defined(my $sid = $self->sessionid)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 3 | require CGI::Cookie; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | $head{'-cookie'} = CGI::Cookie->new(-name => $self->{sessionidname}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 3 | -value => $sid); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | # Set the charset for i18n | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 29 | $head{'-charset'} = $self->charset; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | # Forcibly require - no extra time in normal case, and if | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | # using Apache::Request this needs to be loaded anyways. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 29 | ▶ | return "Content-type: text/html\n\n" if $::TESTING; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 1 | require CGI; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 1 | return CGI::header(%head); # CGI.pm MOD_PERL fanciness | |||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | sub charset { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 29 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
charset: called CC=4 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 29 | ▶ | $self->{charset} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 29 | ▶ | return $self->{charset} || $self->{messages}->charset || 'iso8859-1'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$self->{'charset'} || $self->{'messages'}->charset || 'iso8859-1'
$self->{"charset"} or $self->{"messages"}->charset
MC/DC0%0/2
$self->{'charset'} || $self->{'messages'}->charset || 'iso8859-1'
$self->{"charset"}
$self->{"messages"}->charset
Truth table33%1/3
A or B
A= $self->{"charset"}B= $self->{"messages"}->charset
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | sub lang { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lang: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | ▶ | $self->{lang} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | ▶ | return $self->{lang} || $self->{messages}->lang || 'en_US'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$self->{'lang'} || $self->{'messages'}->lang || 'en_US'
$self->{"lang"} or $self->{"messages"}->lang
MC/DC0%0/2
$self->{'lang'} || $self->{'messages'}->lang || 'en_US'
$self->{"lang"}
$self->{"messages"}->lang
Truth table0%0/3
A or B
A= $self->{"lang"}B= $self->{"messages"}->lang
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | sub dtd { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dtd: called CC=3 SCAR=15.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 14 | ▶ | $self->{dtd} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 14 | ▶ | return '<html>' if $::TESTING; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | # replace special chars in dtd by exec'ing subs | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | my $dtd = $self->{dtd}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | $dtd =~ s/\{(\w+)\}/$self->$1/ge; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | return $dtd; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | sub title { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 127 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
title: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 127 | ▶ | $self->{title} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 127 | ▶ | return $self->{title} if exists $self->{title}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 6 | return toname(basename); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 10 | *script_name = \&action; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | sub action { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 9 | ▶ | local $^W = 0; # -w sucks (still) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
action: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 9 | ▶ | $self->{action} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 9 | ▶ | return $self->{action} if exists $self->{action}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 8 | return basename . $ENV{PATH_INFO}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | sub font { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 339 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
font: called CC=8 SCAR=33.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 339 | ▶ | $self->{font} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 339 | ▶ | return '' unless $self->{font}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 2 | ▶ | return '' if $self->{stylesheet}; # kill fonts for style | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | # Catch for allowable hashref or string | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | my $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | ▶ | my $ref = ref $self->{font} || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
ref $self->{'font'} || ''
MC/DC0%0/1
ref $self->{'font'} || ''
ref $self->{'font'}
Truth table0%0/2
A
A= ref $self->{'font'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | ▶ | if (! $ref) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | # string "arial,helvetica" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | $ret = { face => $self->{font} }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | } elsif ($ref eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | # hack for array [arial,helvetica] from conf | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | $ret = { face => join ',', @{$self->{font}} }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | $ret = $self->{font}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | ▶ | return wantarray ? %$ret : htmltag('font', %$ret); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 10 | *tag = \&start; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | sub start { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 129 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=7 SCAR=20.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 129 | my %attr = htmlattr('form', %$self); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 129 | ▶ | $attr{action} ||= $self->action; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$attr{"action"} ||= $self->action
MC/DC0%0/2
$attr{"action"} ||= $self->action
$attr{"action"}
$self->action
Truth table66%2/3
A ||= B
A= $attr{"action"}B= $self->action
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 129 | ▶ | $attr{method} ||= $self->method; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$attr{"method"} ||= $self->method
MC/DC0%0/2
$attr{"method"} ||= $self->method
$attr{"method"}
$self->method
Truth table33%1/3
A ||= B
A= $attr{"method"}B= $self->method
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 129 | $attr{method} = lc($attr{method}); # xhtml | |||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 129 | ▶ | $self->disabled ? $attr{disabled} = 'disabled' : delete $attr{disabled}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 129 | ▶ | $attr{class} ||= $self->class($self->formname); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$attr{"class"} ||= $self->class($self->formname)
MC/DC50%1/2
$attr{"class"} ||= $self->class($self->formname)
$attr{"class"}
$self->class($self->formname)
Truth table66%2/3
A ||= B
A= $attr{"class"}B= $self->class($self->formname)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | # Bleech, there's no better way to do this...? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | belch "You should really call \$form->script BEFORE \$form->start" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 129 | ▶ | unless $self->{_didscript}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | # A catch for lowercase actions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | belch "Old-style 'onSubmit' action found - should be 'onsubmit'" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 129 | ▶ | if $attr{onSubmit}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 129 | return $self->version . htmltag('form', %attr); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | sub end { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 70 | ▶ | return '</form>'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
end: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | # Need to wrap this or else AUTOLOAD whines (OURATTR missing) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | sub disabled { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 690 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disabled: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 690 | ▶ | $self->{disabled} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 690 | ▶ | return $self->{disabled} ? 'disabled' : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | sub body { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
body: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 14 | ▶ | $self->{body} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 14 | ▶ | $self->{body}{bgcolor} ||= 'white' unless $self->{stylesheet}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{"body"}{"bgcolor"} ||= "white"
MC/DC100%1/1
$self->{"body"}{"bgcolor"} ||= "white"
$self->{"body"}{"bgcolor"}
Truth table100%2/2
A
A= $self->{"body"}{"bgcolor"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 14 | return htmltag('body', $self->{body}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | sub class { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 1490 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
class: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 1490 | ▶ | return undef unless $self->{stylesheet}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 307 | return join '', $self->{styleclass}, @_; # remainder is optional tag | |||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | sub idname { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 752 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
idname: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | $self->{id} = $self->{name} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 752 | ▶ | unless defined $self->{id}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 752 | ▶ | return undef unless $self->{id}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 184 | return join '', $self->{id}, @_; # remainder is optional tag | |||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | sub table { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 106 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | # single hashref kills everything; a list is temporary | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 106 | ▶ | $self->{table} = shift if @_ == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 106 | ▶ | return unless $self->{table}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | # set defaults for numeric table => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 104 | ▶ | $self->{table} = $DEFAULT{table} if $self->{table} == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 104 | my $attr = $self->{table}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 104 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | # if still have args, create a temp hash | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 100 | my %temp = %$attr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 100 | ▶ | while (my $k = shift) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 156 | $temp{$k} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 100 | $attr = \%temp; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 104 | ▶ | return unless $self->{table}; # 0 or unset via table(0) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 104 | ▶ | $attr->{class} ||= $self->class; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$attr->{"class"} ||= $self->class
MC/DC100%2/2
$attr->{"class"} ||= $self->class
$attr->{"class"}
$self->class
Truth table100%3/3
A ||= B
A= $attr->{"class"}B= $self->class
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 104 | return htmltag('table', $attr); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | sub tr { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 218 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tr: called CC=7 SCAR=19.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | # single hashref kills everything; a list is temporary | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 218 | ▶ | $self->{tr} = shift if @_ == 1 && UNIVERSAL::isa($_[0], 'HASH'); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ == 1 and UNIVERSAL::isa($_[0], "HASH")
MC/DC0%0/2
@_ == 1 and UNIVERSAL::isa($_[0], "HASH")
@_ == 1
UNIVERSAL::isa($_[0], "HASH")
Truth table33%1/3
A and B
A= @_ == 1B= UNIVERSAL::isa($_[0], "HASH")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 218 | my $attr = $self->{tr}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 218 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | # if still have args, create a temp hash | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 218 | my %temp = %$attr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 218 | ▶ | while (my $k = shift) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 218 | $temp{$k} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 218 | $attr = \%temp; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | # reduced formatting | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 218 | ▶ | if ($self->{stylesheet}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | # extraneous - inherits from <table> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | #$attr->{class} ||= $self->class($self->{rowname}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 168 | ▶ | $attr->{valign} ||= 'top'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$attr->{"valign"} ||= "top"
MC/DC100%1/1
$attr->{"valign"} ||= "top"
$attr->{"valign"}
Truth table100%2/2
A
A= $attr->{"valign"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 218 | return htmltag('tr', $attr); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | sub th { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
th: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | # single hashref kills everything; a list is temporary | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | ▶ | $self->{th} = shift if @_ == 1 && UNIVERSAL::isa($_[0], 'HASH'); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ == 1 and UNIVERSAL::isa($_[0], "HASH")
MC/DC0%0/2
@_ == 1 and UNIVERSAL::isa($_[0], "HASH")
@_ == 1
UNIVERSAL::isa($_[0], "HASH")
Truth table0%0/3
A and B
A= @_ == 1B= UNIVERSAL::isa($_[0], "HASH")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | my $attr = $self->{th}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | # if still have args, create a temp hash | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | my %temp = %$attr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | ▶ | while (my $k = shift) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | $temp{$k} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | $attr = \%temp; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | # reduced formatting | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | ▶ | if ($self->{stylesheet}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | # extraneous - inherits from <table> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | #$attr->{class} ||= $self->class($self->{labelname}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | ▶ | $attr->{align} ||= $self->{lalign} || 'left'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$attr->{"align"} ||= $self->{"lalign"} || "left"
$self->{'lalign'} || 'left'
MC/DC0%0/2
$attr->{"align"} ||= $self->{"lalign"} || "left"
$attr->{"align"}
$self->{'lalign'}
Truth table0%0/3
A ||= B
A= $attr->{"align"}B= $self->{'lalign'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 0 | return htmltag('th', $attr); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | sub td { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 383 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
td: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | # single hashref kills everything; a list is temporary | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 383 | ▶ | $self->{td} = shift if @_ == 1 && UNIVERSAL::isa($_[0], 'HASH'); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ == 1 and UNIVERSAL::isa($_[0], "HASH")
MC/DC0%0/2
@_ == 1 and UNIVERSAL::isa($_[0], "HASH")
@_ == 1
UNIVERSAL::isa($_[0], "HASH")
Truth table33%1/3
A and B
A= @_ == 1B= UNIVERSAL::isa($_[0], "HASH")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 383 | my $attr = $self->{td}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 383 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | # if still have args, create a temp hash | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 383 | my %temp = %$attr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 383 | ▶ | while (my $k = shift) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 863 | $temp{$k} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 383 | $attr = \%temp; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | # extraneous - inherits from <table> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | #$attr->{class} ||= $self->class($self->{fieldname}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 383 | return htmltag('td', $attr); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | sub div { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 90 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
div: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | # single hashref kills everything; a list is temporary | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 90 | ▶ | $self->{div} = shift if @_ == 1 && UNIVERSAL::isa($_[0], 'HASH'); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ == 1 and UNIVERSAL::isa($_[0], "HASH")
MC/DC0%0/2
@_ == 1 and UNIVERSAL::isa($_[0], "HASH")
@_ == 1
UNIVERSAL::isa($_[0], "HASH")
Truth table33%1/3
A and B
A= @_ == 1B= UNIVERSAL::isa($_[0], "HASH")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 90 | my $attr = $self->{div}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 90 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | # if still have args, create a temp hash | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 90 | my %temp = %$attr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 90 | ▶ | while (my $k = shift) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 172 | $temp{$k} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 90 | $attr = \%temp; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 90 | return htmltag('div', $attr); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | sub submitted { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 13 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
submitted: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 13 | ▶ | my $smnam = shift || $self->submittedname; # temp smnam | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() || $self->submittedname
MC/DC0%0/2
shift() || $self->submittedname
shift()
$self->submittedname
Truth table33%1/3
A || B
A= shift()B= $self->submittedname
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 13 | ▶ | my $smtag = $self->{name} ? "${smnam}_$self->{name}" : $smnam; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 13 | ▶ | if ($self->{params}->param($smtag)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | # If we've been submitted, then we return the value of | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | # the submit tag (which allows multiple submission buttons). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | # Must use an "|| 0E0" or else hitting "Enter" won't cause | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | # $form->submitted to be true (as the button is only sent | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | # across CGI when clicked). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 11 | ▶ | my $sr = $self->{params}->param($self->submitname) || '0E0'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'params'}->param($self->submitname) || '0E0'
MC/DC0%0/1
$self->{'params'}->param($self->submitname) || '0E0'
$self->{'params'}->param($self->submitname)
Truth table50%1/2
A
A= $self->{'params'}->param($self->submitname)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 11 | debug 2, "\$form->submitted() is true, returning $sr"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 11 | return $sr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | # This creates a modified self_url, just including fields (no sessionid, etc) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | sub query_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query_string: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | my @qstr = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | for my $f ($self->fields, $self->keepextras) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | # get all values, but ONLY from CGI | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 0 | push @qstr, join('=', escapeurl($f), escapeurl($_)) for $self->cgi_param($f); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 0 | return join '&', @qstr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | sub self_url { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
self_url: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | return join '?', $self->action, $self->query_string; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | # must forcibly return scalar undef for CGI::Session easiness | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | sub sessionid { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 159 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sessionid: called CC=7 SCAR=20.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 159 | ▶ | $self->{sessionid} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 159 | ▶ | return $self->{sessionid} if $self->{sessionid}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 153 | ▶ | return undef unless $self->{sessionidname}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 153 | my %cookies; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 153 | ▶ | if ($self->{cookies}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 153 | require CGI::Cookie; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 153 | %cookies = CGI::Cookie->fetch; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 153 | ▶ | if (my $cook = $cookies{"$self->{sessionidname}"}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | return $cook->value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 153 | ▶ | return $self->{params}->param($self->{sessionidname}) || undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'params'}->param($self->{'sessionidname'}) || undef
MC/DC0%0/1
$self->{'params'}->param($self->{'sessionidname'}) || undef
$self->{'params'}->param($self->{'sessionidname'})
Truth table50%1/2
A
A= $self->{'params'}->param($self->{'sessionidname'})
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | sub statetags { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 129 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
statetags: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 129 | my @html = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | # get _submitted | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 129 | my $smnam = $self->submittedname; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 129 | ▶ | my $smtag = $self->{name} ? "${smnam}_$self->{name}" : $smnam; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 129 | my $smval = $self->{params}->param($smnam) + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 129 | push @html, htmltag('input', name => $smtag, value => $smval, type => 'hidden'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | # and how about _sessionid | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 129 | ▶ | if (defined(my $sid = $self->sessionid)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | push @html, htmltag('input', name => $self->{sessionidname}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 2 | type => 'hidden', value => $sid); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | # and what page (hooks for ::Multi) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 129 | ▶ | if (defined $self->{page}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | push @html, htmltag('input', name => $self->pagename, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 2 | type => 'hidden', value => $self->{page}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 129 | ▶ | return wantarray ? @html : join "\n", @html; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 10 | *keepextra = \&keepextras; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | sub keepextras { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 129 | ▶ | local $^W = 0; # -w sucks | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keepextras: called CC=13 SCAR=25.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 129 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 129 | my @keep = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 129 | my @html = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | # which ones do they want? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 129 | ▶ | $self->{keepextras} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 129 | ▶ | return '' unless $self->{keepextras}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | # If we set keepextras, then this means that any extra fields that | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | # we've set that are *not* in our fields() will be added to the form | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 10 | ▶ | my $ref = ref $self->{keepextras} || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
ref $self->{'keepextras'} || ''
MC/DC100%1/1
ref $self->{'keepextras'} || ''
ref $self->{'keepextras'}
Truth table100%2/2
A
A= ref $self->{'keepextras'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 10 | ▶ | if ($ref eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 4 | @keep = @{$self->{keepextras}}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | } elsif ($ref) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 0 | puke "Unsupported data structure type '$ref' passed to 'keepextras' option"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | # Set to "1", so must go thru all params, skipping | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | # leading underscore fields and form fields | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 6 | for my $p ($self->{params}->param()) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 50 | ▶ | next if $p =~ /^_/ || $self->{fieldrefs}{$p}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$p =~ /^_/ or $self->{"fieldrefs"}{$p}
MC/DC100%2/2
$p =~ /^_/ or $self->{"fieldrefs"}{$p}
$p =~ /^_/
$self->{"fieldrefs"}{$p}
Truth table100%3/3
A or B
A= $p =~ /^_/B= $self->{"fieldrefs"}{$p}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 32 | push @keep, $p; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | # In array context, we just return names we've resolved | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 10 | ▶ | return @keep if wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | # Make sure to get all values | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 10 | for my $p (@keep) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 40 | ▶ | my @values = $self->{params}->can('multi_param') ? $self->{params}->multi_param($p) : $self->{params}->param($p); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 40 | for my $v (@values) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 40 | debug 1, "keepextras: saving hidden param $p = $v"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 40 | push @html, htmltag('input', name => $p, type => 'hidden', value => $v); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 10 | return join "\n", @html; # wantarray above | |||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | sub javascript { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 165 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
javascript: called CC=6 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 165 | ▶ | $self->{javascript} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | # auto-determine javascript setting based on user agent | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 165 | ▶ | if (lc($self->{javascript}) eq 'auto') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 150 | ▶ | if (exists $ENV{HTTP_USER_AGENT} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $ENV{"HTTP_USER_AGENT"} and $ENV{"HTTP_USER_AGENT"} =~ /lynx|mosaic/i
MC/DC0%0/2
exists $ENV{"HTTP_USER_AGENT"} and $ENV{"HTTP_USER_AGENT"} =~ /lynx|mosaic/i
exists $ENV{"HTTP_USER_AGENT"}
$ENV{"HTTP_USER_AGENT"} =~ /lynx|mosaic/i
Truth table33%1/3
A and B
A= exists $ENV{"HTTP_USER_AGENT"}B= $ENV{"HTTP_USER_AGENT"} =~ /lynx|mosaic/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | && $ENV{HTTP_USER_AGENT} =~ /lynx|mosaic/i) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | # Turn off for old/non-graphical browsers | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 150 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 15 | ▶ | return $self->{javascript} if exists $self->{javascript}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | # Turn on for all other browsers by default. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | # I suspect this process should be reversed, only | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | # showing JavaScript on those browsers we know accept | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | # it, but maintaining a full list will result in this | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | # module going out of date and having to be updated. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | sub jsname { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 132 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
jsname: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | return $self->{name} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | ? (join '_', $self->{jsname}, tovar($self->{name})) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 132 | ▶ | : $self->{jsname}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | sub script { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 132 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
script: called CC=15 SCAR=28.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | # get validate() function name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 132 | ▶ | my $jsname = $self->jsname || puke "Must have 'jsname' if 'javascript' is on"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->jsname || &puke(q[Must have 'jsname' if 'javascript' is on])
MC/DC0%0/2
$self->jsname || &puke(q[Must have 'jsname' if 'javascript' is on])
$self->jsname
&puke(q[Must have 'jsname' if 'javascript' is on])
Truth table33%1/3
A || B
A= $self->jsnameB= &puke(q[Must have 'jsname' if 'javascript' is on])
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 132 | ▶ | my $jspre = $self->jsprefix || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->jsprefix || ''
MC/DC0%0/1
$self->jsprefix || ''
$self->jsprefix
Truth table50%1/2
A
A= $self->jsprefix
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | # "counter" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 132 | $self->{_didscript} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 132 | ▶ | return '' unless $self->javascript; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | # code for misc non-validate functions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 120 | my $jsmisc = $self->script_growable # code to grow growable fields, if any | |||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | . $self->script_otherbox; # code to enable/disable the "other" box | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | # custom user jsfunc option for w/i validate() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 120 | ▶ | my $jsfunc = $self->jsfunc || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->jsfunc || ''
MC/DC100%1/1
$self->jsfunc || ''
$self->jsfunc
Truth table100%2/2
A
A= $self->jsfunc
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 120 | ▶ | my $jshead = $self->jshead || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->jshead || ''
MC/DC0%0/1
$self->jshead || ''
$self->jshead
Truth table50%1/2
A
A= $self->jshead
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | # expand per-field validation functions, but | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | # only if we are not using Data::FormValidator | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 120 | ▶ | unless (UNIVERSAL::isa($self->{validate}, 'Data::FormValidator')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 120 | for ($self->field) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 353 | $jsfunc .= $_->script; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | # skip out if we have nothing useful | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | 120 | ▶ | return '' unless $jsfunc || $jsmisc || $jshead; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$jsfunc or $jsmisc or $jshead
$jsfunc or $jsmisc
MC/DC66%2/3
$jsfunc or $jsmisc or $jshead
$jsfunc
$jsmisc
$jshead
Truth table75%3/4
A or B or C
A= $jsfuncB= $jsmiscC= $jshead
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | # prefix with opening code | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 38 | ▶ | if ($jsfunc) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 33 | $jsfunc = <<EOJ1 . $jsfunc . <<EOJ2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | function $jsname (form) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | var alertstr = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | var invalid = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | var invalid_fields = new Array(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | EOJ1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | if (invalid > 0 || alertstr != '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | EOJ2 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | # Check to see if we have our own jserror callback on form failure | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | # if not, then use the builtin one. Aka jsalert | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 33 | ▶ | if (my $jse = $self->jserror) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 0 | $jsfunc .= " return $jse(form, invalid, alertstr, invalid_fields);\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | # Finally, close our JavaScript if it was opened, wrapping in <script> tags | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | # We do a regex trick to turn "%s" into "+invalid+" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | 33 | (my $alertstart = $self->{messages}->js_invalid_start) =~ s/%s/'+invalid+'/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 33 | (my $alertend = $self->{messages}->js_invalid_end) =~ s/%s/'+invalid+'/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 33 | $jsfunc .= <<EOJS; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | if (! invalid) invalid = 'The following'; // catch for programmer error | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | alert('$alertstart'+'\\n\\n' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | +alertstr+'\\n'+'$alertend'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | EOJS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | # Close the function | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 33 | ▶ | if (my $jss = $self->jsvalid) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 0 | $jsfunc .= " }\n return $jss(form);\n}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | 33 | $jsfunc .= " }\n return true; // all checked ok\n}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | # Must set our onsubmit to call validate() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | # Unfortunately, this introduces the requirement that script() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | # must be generated/called before start() in our template engines. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | # Fortunately, that usually happens anyways. Still sucks. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 33 | ▶ | $self->{onsubmit} ||= "return $jsname(this);"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"onsubmit"} ||= "return $jsname(this);"
MC/DC100%1/1
$self->{"onsubmit"} ||= "return $jsname(this);"
$self->{"onsubmit"}
Truth table100%2/2
A
A= $self->{"onsubmit"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | # set <script> now to the expanded javascript | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | 38 | return '<script type="text/javascript">' | |||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | . "<!-- hide from old browsers\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | #. "<![CDATA[\n" # fucking web "standards" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | . $jshead . $jsmisc . $jsfunc | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | #. "\n]]>" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | . "//-->\n</script>"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | sub script_growable { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | 120 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
script_growable: called CC=7 SCAR=20.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 120 | ▶ | return '' unless my @growable = grep { $_->growable } $self->field; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | 2 | ▶ | my $jspre = $self->jsprefix || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->jsprefix || ''
MC/DC0%0/1
$self->jsprefix || ''
$self->jsprefix
Truth table50%1/2
A
A= $self->jsprefix
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 2 | my $jsmisc = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | 2 | my $grow = $self->growname; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | 2 | $jsmisc .= <<EOJS; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | var ${jspre}counter = new Object; // for assigning unique ids; keyed by field name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | var ${jspre}limit = new Object; // for limiting the size of growable fields | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | function ${jspre}grow (baseID) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | // inititalize the counter for this ID | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | if (isNaN(${jspre}counter[baseID])) ${jspre}counter[baseID] = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | // don't go past the growth limit for this field | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | if (${jspre}counter[baseID] >= ${jspre}limit[baseID]) return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | var base = document.getElementById(baseID + '_' + (${jspre}counter[baseID] - 1)); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | // we are inserting after the last field | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | insertPoint = base.nextSibling; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | // line break | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | base.parentNode.insertBefore(document.createElement('br'), insertPoint); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | var dup = base.cloneNode(true); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | dup.setAttribute('id', baseID + '_' + ${jspre}counter[baseID]); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | base.parentNode.insertBefore(dup, insertPoint); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | // add some padding space between the field and the "add field" button | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | base.parentNode.insertBefore(document.createTextNode(' '), insertPoint); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | ${jspre}counter[baseID]++; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | // disable the "add field" button if we are at the limit | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | if (${jspre}counter[baseID] >= ${jspre}limit[baseID]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | var addButton = document.getElementById('$grow' + '_' + baseID); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | addButton.setAttribute('disabled', 'disabled'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | EOJS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | # initialize growable counters | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | 2 | for (@growable) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | 2 | my $count = scalar(my @v = $_->values); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | 2 | ▶ | $jsmisc .= "${jspre}counter['$_'] = $count;\n" if $count > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | # assume that values of growable > 1 provide limits | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 2 | my $limit = $_->growable; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | 2 | ▶ | if ($limit && $limit ne 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$limit and $limit ne 1
MC/DC0%0/2
$limit and $limit ne 1
$limit
$limit ne 1
Truth table33%1/3
A and B
A= $limitB= $limit ne 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | 0 | $jsmisc .= "${jspre}limit['$_'] = $limit;\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | 2 | return $jsmisc; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | sub script_otherbox { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | 120 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
script_otherbox: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | 120 | ▶ | return '' unless my @otherable = grep { $_->other } $self->field; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 5 | ▶ | my $jspre = $self->jsprefix || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->jsprefix || ''
MC/DC0%0/1
$self->jsprefix || ''
$self->jsprefix
Truth table50%1/2
A
A= $self->jsprefix
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 5 | my $jsmisc = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 5 | $jsmisc .= <<EOJS; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | // turn on/off any "other"fields | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | function ${jspre}other_on (othername) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | var box = document.getElementById(othername); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | box.removeAttribute('disabled'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | function ${jspre}other_off (othername) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | var box = document.getElementById(othername); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | box.setAttribute('disabled', 'disabled'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | EOJS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 5 | return $jsmisc; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | sub noscript { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 15 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
noscript: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | # no state is kept and no args are allowed | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 15 | ▶ | puke "No args allowed for \$form->noscript" if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 15 | ▶ | return '' unless $self->javascript; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 15 | return '<noscript>' . $self->invalid_tag($self->{messages}->js_noscript) . '</noscript>'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | sub submits { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | 123 | ▶ | local $^W = 0; # -w sucks | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
submits: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 123 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | # handle the submit button(s) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | # logic is a little complicated - if set but to a false value, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | # then leave off. otherwise use as the value for the tags. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | 123 | my @submit = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | 123 | my $sn = $self->{submitname}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | 123 | my $sc = $self->class($self->{buttonname}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | 123 | ▶ | if (ref $self->{submit} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | # multiple buttons + JavaScript - dynamically set the _submit value | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 17 | ▶ | my @oncl = $self->javascript | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | ? (onclick => "this.form.$sn.value = this.value;") : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | 17 | my $i=1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | 17 | for my $subval (autodata $self->{submit}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 40 | ▶ | my $si = $i > 1 ? "_$i" : ''; # number with second one | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | 40 | push @submit, { type => 'submit', | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | id => "$self->{name}$sn$si", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | class => $sc, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | name => $sn, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | value => $subval, @oncl }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | 40 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | # show the text on the button | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | my $subval = $self->{submit} eq 1 ? $self->{messages}->form_submit_default | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | 106 | ▶ | : $self->{submit}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | 106 | push @submit, { type => 'submit', | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | id => "$self->{name}$sn", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | class => $sc, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | name => $sn, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | value => $subval }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | 123 | ▶ | return wantarray ? @submit : [ map { htmltag('input', $_) } @submit ]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | sub submit { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | 128 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
submit: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | 128 | ▶ | $self->{submit} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | 128 | ▶ | return '' if ! $self->{submit} || $self->static || $self->disabled; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not $self->{"submit"} or $self->static or $self->disabled
not $self->{"submit"} or $self->static
MC/DC66%2/3
not $self->{"submit"} or $self->static or $self->disabled
not $self->{"submit"}
$self->static
$self->disabled
Truth table75%3/4
not(A) or B or C
A= not $self->{"submit"}B= $self->staticC= $self->disabled
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | # no newline on buttons regardless of setting | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | 122 | return join '', map { htmltag('input', $_) } $self->submits(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | sub reset { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | 129 | ▶ | local $^W = 0; # -w sucks | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: called CC=6 SCAR=18.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | 129 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | 129 | ▶ | $self->{reset} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | 129 | ▶ | return '' if ! $self->{reset} || $self->static || $self->disabled; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not $self->{"reset"} or $self->static or $self->disabled
not $self->{"reset"} or $self->static
MC/DC33%1/3
not $self->{"reset"} or $self->static or $self->disabled
not $self->{"reset"}
$self->static
$self->disabled
Truth table50%2/4
not(A) or B or C
A= not $self->{"reset"}B= $self->staticC= $self->disabled
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | 5 | my $sc = $self->class($self->{buttonname}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | # similar to submit(), but a little simpler ;-) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | my $reset = $self->{reset} eq 1 ? $self->{messages}->form_reset_default | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | 5 | ▶ | : $self->{reset}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | 5 | my $rn = $self->resetname; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | 5 | return htmltag('input', type => 'reset', | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | id => "$self->{name}$rn", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | class => $sc, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | name => $rn, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | value => $reset); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | sub text { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | 59 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | 59 | ▶ | $self->{text} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | # having any required fields changes the leading text | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | 59 | my $req = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | 59 | my $inv = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | 59 | for ($self->fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | 173 | ▶ | $req++ if $_->required; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | 173 | ▶ | $inv++ if $_->invalid; # failed validate() | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | 59 | ▶ | unless ($self->static || $self->disabled) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->static or $self->disabled
MC/DC100%2/2
$self->static or $self->disabled
$self->static
$self->disabled
Truth table100%3/3
A or B
A= $self->staticB= $self->disabled
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | # only show either invalid or required text | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | return $self->{text} .'<p>'. sprintf($self->{messages}->form_invalid_text, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | 56 | ▶ | $inv, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | $self->invalid_tag).'</p>' if $inv; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | return $self->{text} .'<p>'. sprintf($self->{messages}->form_required_text, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | 54 | ▶ | $self->required_tag).'</p>' if $req; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | 44 | return $self->{text}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | sub invalid_tag { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | 19 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
invalid_tag: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | 19 | ▶ | my $label = shift || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || ''
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | my @tags = $self->{stylesheet} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | 19 | ▶ | ? (qq(<span class="$self->{styleclass}_invalid">), '</span>') | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | : ('<font color="#cc0000"><b>', '</b></font>'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | 19 | ▶ | return wantarray ? @tags : join $label, @tags; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | sub required_tag { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | 48 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
required_tag: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | 48 | ▶ | my $label = shift || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || ''
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | my @tags = $self->{stylesheet} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | 48 | ▶ | ? (qq(<span class="$self->{styleclass}_required">), '</span>') | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | : ('<b>', '</b>'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | 48 | ▶ | return wantarray ? @tags : join $label, @tags; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | sub cgi_param { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | 9 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cgi_param: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | 9 | $self->{params}->param(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | sub tmpl_param { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | 74 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tmpl_param: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | 74 | ▶ | if (my $key = shift) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | return @_ ? $self->{tmplvar}{$key} = shift | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | 4 | ▶ | : $self->{tmplvar}{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | # return hash or key/value pairs | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | 70 | ▶ | my $hr = $self->{tmplvar} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'tmplvar'} || {}
MC/DC100%1/1
$self->{'tmplvar'} || {}
$self->{'tmplvar'}
Truth table100%2/2
A
A= $self->{'tmplvar'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | 70 | ▶ | return wantarray ? %$hr : $hr; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | sub version { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | # Hidden trailer. If you perceive this as annoying, let me know and I | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | # may remove it. It's supposed to help. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | 129 | ▶ | return '' if $::TESTING; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version: called CC=3 SCAR=19.2
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | 0 | ▶ | if (ref $_[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | 0 | return "\n<!-- Generated by CGI::FormBuilder v$VERSION available from www.formbuilder.org -->\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | 0 | return "CGI::FormBuilder v$VERSION by Nate Wiger. All Rights Reserved.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | sub values { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | 49 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
values: called CC=10 SCAR=24.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | 49 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | 49 | $self->{values} = arghash(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | 49 | my %val = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | 49 | my @val = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | # We currently make two passes, first getting the values | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | # and storing them into a temp hash, and then going thru | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | # the fields and picking up the values and attributes. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | 49 | local $" = ','; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | 49 | debug 1, "\$form->{values} = ($self->{values})"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | # Using isa() allows objects to transparently fit in here | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | 49 | ▶ | if (UNIVERSAL::isa($self->{values}, 'CODE')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | # it's a sub; lookup each value in turn | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | 0 | for my $key (&{$self->{values}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | # always assume an arrayref of values... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | 0 | $val{$key} = [ &{$self->{values}}($key) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | 0 | debug 2, "setting values from \\&code(): $key = (@{$val{$key}})"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | } elsif (UNIVERSAL::isa($self->{values}, 'HASH')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | # must lc all the keys since we're case-insensitive, then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | # we turn our values hashref into an arrayref on the fly | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | 47 | my @v = autodata $self->{values}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | 47 | ▶ | while (@v) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | 91 | my $key = lc shift @v; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | 91 | $val{$key} = [ autodata shift @v ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | 91 | debug 2, "setting values from HASH: $key = (@{$val{$key}})"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | } elsif (UNIVERSAL::isa($self->{values}, 'ARRAY')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | # also accept an arrayref which is walked sequentially below | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | 2 | debug 2, "setting values from ARRAY: (walked below)"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | 2 | @val = autodata $self->{values}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | 0 | puke "Unsupported operand to 'values' option - must be \\%hash, \\&sub, or \$object"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | # redistribute values across all existing fields | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | 49 | for ($self->fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | 118 | ▶ | my $v = $val{lc($_)} || shift @val; # use array if no value | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$val{lc $_} || shift @val
MC/DC100%2/2
$val{lc $_} || shift @val
$val{lc $_}
shift @val
Truth table100%3/3
A || B
A= $val{lc $_}B= shift @val
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | 118 | ▶ | $_->field(value => $v) if defined $v; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | sub name { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | 60 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | 60 | ▶ | @_ ? $self->{name} = shift : $self->{name}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | sub nameopts { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nameopts: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | 0 | $self->{nameopts} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | 0 | for ($self->fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | 0 | $_->field(nameopts => $self->{nameopts}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | 0 | return $self->{nameopts}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | sub sortopts { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sortopts: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | 0 | $self->{sortopts} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | 0 | for ($self->fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | 0 | $_->field(sortopts => $self->{sortopts}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | 0 | return $self->{sortopts}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | sub selectnum { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
selectnum: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | 0 | $self->{selectnum} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | 0 | for ($self->fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | 0 | $_->field(selectnum => $self->{selectnum}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | 0 | return $self->{selectnum}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | sub options { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | 0 | $self->{options} = arghash(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | 0 | my %val = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | # same case-insensitization as $form->values | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | 0 | my @v = autodata $self->{options}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | 0 | ▶ | while (@v) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | 0 | my $key = lc shift @v; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | 0 | $val{$key} = [ autodata shift @v ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | 0 | for ($self->fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | 0 | my $v = $val{lc($_)}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | 0 | ▶ | $_->field(options => $v) if defined $v; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | 0 | return $self->{options}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | sub labels { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
labels: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | 0 | $self->{labels} = arghash(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | 0 | my %val = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | # same case-insensitization as $form->values | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | 0 | my @v = autodata $self->{labels}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | 0 | ▶ | while (@v) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | 0 | my $key = lc shift @v; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | 0 | $val{$key} = [ autodata shift @v ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | 0 | for ($self->fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | 0 | my $v = $val{lc($_)}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | 0 | ▶ | $_->field(label => $v) if defined $v; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | 0 | return $self->{labels}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | # Note that validate does not work like a true accessor | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | sub validate { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | 19 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate: called CC=11 SCAR=37.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | 19 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | 0 | ▶ | if (ref $_[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | # this'll either be a hashref or a DFV object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | 0 | $self->{validate} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | } elsif (@_ % 2 == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | # someone passed a hash-as-list | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | 0 | $self->{validate} = { @_ }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | } elsif (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | # just one argument we'll interpret as a DFV profile name; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | # an odd number > 1 is probably a typo... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | 0 | puke "Odd number of elements passed to validate"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | 19 | my $ok = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | 19 | ▶ | if (UNIVERSAL::isa($self->{validate}, 'Data::FormValidator')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | 0 | ▶ | my $profile_name = shift || 'fb'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 'fb'
MC/DC0%0/1
shift() || 'fb'
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | 0 | debug 1, "validating fields via the '$profile_name' profile"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | # hang on to the DFV results, for things like DBIx::Class::WebForm | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | 0 | $self->{dfv_results} = $self->{validate}->check($self, $profile_name); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | # mark the invalid fields | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | my @invalid_fields = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | $self->{dfv_results}->invalid, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | $self->{dfv_results}->missing, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | 0 | for my $field_name (@invalid_fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | 0 | $self->field( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | name => $field_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | invalid => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | # validation failed | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | 0 | ▶ | $ok = 0 if @invalid_fields > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | 19 | debug 1, "validating all fields via \$form->validate"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1374 | 19 | for ($self->fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1375 | 41 | ▶ | $ok = 0 unless $_->validate; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | 19 | debug 1, "validation done, ok = $ok (should be 1)"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | 19 | return $ok; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1382 | sub confirm { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1383 | # This is nothing more than a special wrapper around render() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1384 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
confirm: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1385 | 0 | ▶ | my $date = $::TESTING ? 'LOCALTIME' : localtime(); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1386 | 0 | ▶ | $self->{text} ||= sprintf $self->{messages}->form_confirm_text, $date; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"text"} ||= sprintf($self->{"messages"}->form_confirm_text, $date)
MC/DC0%0/2
$self->{"text"} ||= sprintf($self->{"messages"}->form_confirm_text, $date)
$self->{"text"}
sprintf($self->{"messages"}->form_confirm_text, $date)
Truth table0%0/3
A ||= B
A= $self->{"text"}B= sprintf($self->{"messages"}->form_confirm_text, $date)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1387 | 0 | $self->{static} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1388 | 0 | return $self->render(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1390 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1391 | # Prepare a template | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1392 | sub prepare { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1393 | 70 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1394 | 70 | debug 1, "Calling \$form->prepare(@_)"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1395 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1396 | # Build a big hashref of data that can be used by the template | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1397 | # engine. Templates then have the ability to expand this however | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1398 | # they see fit. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1399 | 70 | my %tmplvar = $self->tmpl_param; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1400 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1401 | # This is based on the original Template Toolkit render() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1402 | 70 | for my $field ($self->field) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1403 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1404 | # Extract value since used often | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1405 | 201 | my @value = $field->tag_value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1406 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1407 | # Create a struct for each field | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1408 | 201 | $tmplvar{field}{"$field"} = { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1409 | %$field, # gets invalid/missing/required | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1410 | field => $field->tag, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1411 | value => $value[0], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1412 | values => \@value, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1413 | options => [$field->options], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1414 | label => $field->label, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1415 | type => $field->type, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1416 | comment => $field->comment, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1417 | nameopts => $field->nameopts, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1418 | cleanopts => $field->cleanopts, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1419 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1420 | # Force-stringify "$field" to get name() under buggy Perls | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1421 | 201 | $tmplvar{field}{"$field"}{error} = $field->error; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1423 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1424 | # Must generate JS first because it affects the others. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1425 | # This is a bit action-at-a-distance, but I just can't | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1426 | # figure out a way around it. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1427 | 70 | debug 2, "\$tmplvar{jshead} = \$self->script"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1428 | 70 | $tmplvar{jshead} = $self->script; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1429 | 70 | debug 2, "\$tmplvar{title} = \$self->title"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1430 | 70 | $tmplvar{title} = $self->title; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1431 | 70 | debug 2, "\$tmplvar{start} = \$self->start . \$self->statetags . \$self->keepextras"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1432 | 70 | $tmplvar{start} = $self->start . $self->statetags . $self->keepextras; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1433 | 70 | debug 2, "\$tmplvar{submit} = \$self->submit"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1434 | 70 | $tmplvar{submit} = $self->submit; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1435 | 70 | debug 2, "\$tmplvar{reset} = \$self->reset"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1436 | 70 | $tmplvar{reset} = $self->reset; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1437 | 70 | debug 2, "\$tmplvar{end} = \$self->end"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1438 | 70 | $tmplvar{end} = $self->end; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1439 | 70 | debug 2, "\$tmplvar{invalid} = \$self->invalid"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1440 | 70 | $tmplvar{invalid} = $self->invalid; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1441 | 70 | debug 2, "\$tmplvar{required} = \$self->required"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1442 | 70 | $tmplvar{required} = $self->required; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1443 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1444 | 70 | my $fieldsets = $self->fieldsets; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1445 | 70 | for my $key (keys %$fieldsets) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1446 | $tmplvar{fieldset}{$key} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1447 | name => $key, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1448 | 74 | label => $fieldsets->{$key}, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1450 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1451 | 70 | $tmplvar{fieldsets} = [ map $tmplvar{fieldset}{$_}, $self->fieldsets ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1452 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1453 | 70 | debug 2, "\$tmplvar{fields} = [ map \$tmplvar{field}{\$_}, \$self->field ]"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1454 | 70 | $tmplvar{fields} = [ map $tmplvar{field}{$_}, $self->field ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1455 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1456 | 70 | ▶ | return wantarray ? %tmplvar : \%tmplvar; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1458 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1459 | sub render { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1460 | 70 | ▶ | local $^W = 0; # -w sucks | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=17 SCAR=29.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1461 | 70 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1462 | 70 | debug 1, "starting \$form->render(@_)"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1463 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1464 | # any arguments are used to make permanent changes to the $form | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1465 | 70 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1466 | 1 | ▶ | puke "Odd number of arguments passed into \$form->render()" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1467 | unless @_ % 2 == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1468 | 1 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1469 | 3 | my $k = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1470 | 3 | $self->$k(shift); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1471 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1472 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1473 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1474 | # check for engine type | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1475 | 70 | my $mod; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1476 | 70 | my $ref = ref $self->{template}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1477 | 70 | ▶ | if (! $ref && $self->{template}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $ref and $self->{"template"}
MC/DC0%0/2
not $ref and $self->{"template"}
not $ref
$self->{"template"}
Truth table66%2/3
not(A) and B
A= not $refB= $self->{"template"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1478 | # "legacy" string filename for HTML::Template; redo format | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1479 | # modifying $self object is ok because it's compatible | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1480 | $self->{template} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1481 | type => 'HTML', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1482 | filename => $self->{template}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1483 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1484 | 0 | $ref = 'HASH'; # tricky | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1485 | 0 | debug 2, "rewrote 'template' option since found filename"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1486 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1487 | # Get ourselves ready | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1488 | 70 | $self->{prepare} = $self->prepare; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1489 | # weaken($self->{prepare}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1490 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1491 | 70 | my $opt; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1492 | 70 | ▶ | if ($ref eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1493 | # must copy to avoid destroying | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1494 | 12 | $opt = { %{ $self->{template} } }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1495 | 12 | ▶ | $mod = ucfirst(delete $opt->{type} || 'HTML'); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $opt->{'type'} || 'HTML'
MC/DC100%1/1
delete $opt->{'type'} || 'HTML'
delete $opt->{'type'}
Truth table100%2/2
A
A= delete $opt->{'type'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1496 | } elsif ($ref eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1497 | # subroutine wrapper | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1498 | 0 | return &{$self->{template}}($self); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1499 | } elsif (UNIVERSAL::can($self->{template}, 'render')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1500 | # instantiated object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1501 | 0 | return $self->{template}->render($self); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1502 | } elsif ($ref) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1503 | 0 | puke "Unsupported operand to 'template' option - must be \\%hash, \\&sub, or \$object w/ render()"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1504 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1505 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1506 | # load user-specified rendering module, or builtin rendering | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1507 | 70 | ▶ | $mod ||= 'Builtin'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$mod ||= "Builtin"
MC/DC100%1/1
$mod ||= "Builtin"
$mod
Truth table100%2/2
A
A= $mod
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1508 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1509 | # user can give 'Their::Complete::Module' or an 'IncludedAdapter' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1510 | 70 | ▶ | $mod = join '::', __PACKAGE__, 'Template', $mod unless $mod =~ /::/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1511 | 70 | debug 1, "loading $mod for 'template' option"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1512 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1513 | # load module | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1514 | 70 | eval "require $mod"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1515 | 70 | ▶ | puke "Bad template engine $mod: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1516 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1517 | # create new object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1518 | #CGI::FormBuilder::Template::Builtin | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1519 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1520 | 63 | my $tmpl = $mod->new($opt); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1521 | # Experiemental: Alter tag names as we're rendering, to support | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1522 | # Ajaxian markup schemes that use their own tags (Backbase, Dojo, etc) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1523 | 63 | local %CGI::FormBuilder::Util::TAGNAMES; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1524 | 63 | ▶ | while (my($k,$v) = each %{$self->{tagnames}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1525 | 9 | $CGI::FormBuilder::Util::TAGNAMES{$k} = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1526 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1527 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1528 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1529 | # Call the engine's prepare too, if it exists | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1530 | # Give it the form object so it can do what it wants | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1531 | # This will have all of the prepared data in {prepare} anyways | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1532 | 63 | ▶ | if ($tmpl && UNIVERSAL::can($tmpl, 'prepare')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$tmpl and UNIVERSAL::can($tmpl, "prepare")
MC/DC50%1/2
$tmpl and UNIVERSAL::can($tmpl, "prepare")
$tmpl
UNIVERSAL::can($tmpl, "prepare")
Truth table66%2/3
A and B
A= $tmplB= UNIVERSAL::can($tmpl, "prepare")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1533 | 59 | $tmpl->prepare($self); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1534 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1535 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1536 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1537 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1538 | # dispatch to engine, prepend header | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1539 | 63 | debug 1, "returning $tmpl->render($self->{prepare})"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1540 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1541 | 63 | my $ret = $self->header . $tmpl->render($self->{prepare}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1542 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1543 | #we have a circular reference but we need to kill it after setting up return | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1544 | 63 | weaken($self->{prepare}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1545 | 63 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1546 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1547 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1548 | # These routines should be moved to ::Mail or something since they're rarely used | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1549 | sub mail () { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1550 | # This is a very generic mail handler | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1551 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mail: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1552 | 0 | my $args = arghash(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1553 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1554 | # Where does the mailer live? Must be sendmail-compatible | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1555 | 0 | my $mailer = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1556 | 0 | ▶ | unless ($mailer = $args->{mailer} && -x $mailer) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args->{'mailer'} && -x $mailer
MC/DC0%0/2
$args->{'mailer'} && -x $mailer
$args->{'mailer'}
-x $mailer
Truth table0%0/3
A && B
A= $args->{'mailer'}B= -x $mailer
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1557 | 0 | for my $sendmail (qw(/usr/lib/sendmail /usr/sbin/sendmail /usr/bin/sendmail)) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1558 | 0 | ▶ | if (-x $sendmail) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1559 | 0 | $mailer = "$sendmail -t"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1560 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1561 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1562 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1563 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1564 | 0 | ▶ | unless ($mailer) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1565 | 0 | belch "Cannot find a sendmail-compatible mailer; use mailer => '/path/to/mailer'"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1566 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1567 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1568 | 0 | ▶ | unless ($args->{to}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1569 | 0 | belch "Missing required 'to' argument; cannot continue without recipient"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1570 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1571 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1572 | 0 | ▶ | if ($args->{from}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1573 | 0 | (my $from = $args->{from}) =~ s/"/\\"/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1574 | 0 | $mailer .= qq( -f "$from"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1575 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1576 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1577 | 0 | debug 1, "opening new mail to $args->{to}"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1578 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1579 | # untaint | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1580 | 0 | my $oldpath = $ENV{PATH}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1581 | 0 | $ENV{PATH} = '/usr/bin:/usr/sbin'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1582 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1583 | 0 | ▶ | open(MAIL, "|$mailer >/dev/null 2>&1") || next; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1584 | 0 | print MAIL "From: $args->{from}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1585 | 0 | print MAIL "To: $args->{to}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1586 | 0 | ▶ | print MAIL "Cc: $args->{cc}\n" if $args->{cc}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1587 | 0 | ▶ | print MAIL "Content-Type: text/plain; charset=\"" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1588 | . $self->charset . "\"\n" if $self->charset; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1589 | 0 | print MAIL "Subject: $args->{subject}\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1590 | 0 | print MAIL "$args->{text}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1591 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1592 | # retaint | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1593 | 0 | $ENV{PATH} = $oldpath; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1594 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1595 | 0 | return close(MAIL); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1596 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1597 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1598 | sub mailconfirm () { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1599 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1600 | # This prints out a very generic message. This should probably | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1601 | # be much better, but I suspect very few if any people will use | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1602 | # this method. If you do, let me know and maybe I'll work on it. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1603 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1604 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mailconfirm: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1605 | 0 | ▶ | my $to = shift unless (@_ > 1); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1606 | 0 | my $args = arghash(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1607 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1608 | # must have a "to" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1609 | 0 | ▶ | return unless $args->{to} ||= $to; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args->{"to"} ||= $to
MC/DC0%0/2
$args->{"to"} ||= $to
$args->{"to"}
$to
Truth table0%0/3
A ||= B
A= $args->{"to"}B= $to
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1610 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1611 | # defaults | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1612 | 0 | ▶ | $args->{from} ||= 'auto-reply'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args->{"from"} ||= "auto-reply"
MC/DC0%0/1
$args->{"from"} ||= "auto-reply"
$args->{"from"}
Truth table0%0/2
A
A= $args->{"from"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1613 | 0 | ▶ | $args->{subject} ||= sprintf $self->{messages}->mail_confirm_subject, $self->title; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$args->{"subject"} ||= sprintf($self->{"messages"}->mail_confirm_subject, $self->title)
MC/DC0%0/2
$args->{"subject"} ||= sprintf($self->{"messages"}->mail_confirm_subject, $self->title)
$args->{"subject"}
sprintf($self->{"messages"}->mail_confirm_subject, $self->title)
Truth table0%0/3
A ||= B
A= $args->{"subject"}B= sprintf($self->{"messages"}->mail_confirm_subject, $self->title)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1614 | 0 | ▶ | $args->{text} ||= sprintf $self->{messages}->mail_confirm_text, scalar localtime(); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$args->{"text"} ||= sprintf($self->{"messages"}->mail_confirm_text, scalar localtime())
MC/DC0%0/2
$args->{"text"} ||= sprintf($self->{"messages"}->mail_confirm_text, scalar localtime())
$args->{"text"}
sprintf($self->{"messages"}->mail_confirm_text, scalar localtime())
Truth table0%0/3
A ||= B
A= $args->{"text"}B= sprintf($self->{"messages"}->mail_confirm_text, scalar localtime())
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1615 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1616 | 0 | debug 1, "mailconfirm() called, subject = '$args->{subject}'"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1617 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1618 | 0 | $self->mail($args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1619 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1620 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1621 | sub mailresults () { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1622 | # This is a wrapper around mail() that sends the form results | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1623 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mailresults: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1624 | 0 | my $args = arghash(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1625 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1626 | 0 | ▶ | if (exists $args->{plugin}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1627 | 0 | my $lib = "CGI::FormBuilder::Mail::$args->{plugin}"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1628 | 0 | eval "use $lib"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1629 | 0 | ▶ | puke "Cannot use mailresults() plugin '$lib': $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1630 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1631 | 0 | my $plugin = $lib->new( form => $self, %$args ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1632 | 0 | $plugin->mailresults(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1633 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1634 | 0 | ▶ | puke "Could not mailresults() with plugin '$lib': $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1635 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1636 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1637 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1638 | # Get the field separator to use | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1639 | 0 | ▶ | my $delim = $args->{delimiter} || ': '; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'delimiter'} || ': '
MC/DC0%0/1
$args->{'delimiter'} || ': '
$args->{'delimiter'}
Truth table0%0/2
A
A= $args->{'delimiter'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1640 | 0 | ▶ | my $join = $args->{joiner} || $"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$args->{'joiner'} || $"
MC/DC0%0/2
$args->{'joiner'} || $"
$args->{'joiner'}
$"
Truth table0%0/3
A || B
A= $args->{'joiner'}B= $"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1641 | 0 | ▶ | my $sep = $args->{separator} || "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'separator'} || "\n"
MC/DC0%0/1
$args->{'separator'} || "\n"
$args->{'separator'}
Truth table0%0/2
A
A= $args->{'separator'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1642 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1643 | # subject default | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1644 | 0 | ▶ | $args->{subject} ||= sprintf $self->{messages}->mail_results_subject, $self->title; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$args->{"subject"} ||= sprintf($self->{"messages"}->mail_results_subject, $self->title)
MC/DC0%0/2
$args->{"subject"} ||= sprintf($self->{"messages"}->mail_results_subject, $self->title)
$args->{"subject"}
sprintf($self->{"messages"}->mail_results_subject, $self->title)
Truth table0%0/3
A ||= B
A= $args->{"subject"}B= sprintf($self->{"messages"}->mail_results_subject, $self->title)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1645 | 0 | debug 1, "mailresults() called, subject = '$args->{subject}'"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1646 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1647 | 0 | ▶ | if ($args->{skip}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1648 | 0 | ▶ | if ($args->{skip} =~ m#^m?(\S)(.*)\1$#) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1649 | 0 | ($args->{skip} = $2) =~ s/\\\//\//g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1650 | 0 | $args->{skip} =~ s/\//\\\//g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1651 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1652 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1653 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1654 | 0 | my @form = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1655 | 0 | for my $field ($self->fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1656 | 0 | ▶ | if ($args->{skip} && $field =~ /$args->{skip}/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args->{"skip"} and $field =~ /$args->{"skip"}/
MC/DC0%0/2
$args->{"skip"} and $field =~ /$args->{"skip"}/
$args->{"skip"}
$field =~ /$args->{"skip"}/
Truth table0%0/3
A and B
A= $args->{"skip"}B= $field =~ /$args->{"skip"}/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1657 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1658 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1659 | 0 | my $v = join $join, $field->value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1660 | 0 | ▶ | $field = $field->label if $args->{labels}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1661 | 0 | push @form, "$field$delim$v"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1662 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1663 | 0 | my $text = join $sep, @form; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1664 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1665 | 0 | $self->mail(%$args, text => $text); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1666 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1667 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1668 | 119 | ▶ | sub DESTROY { 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1669 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1670 | # This is used to access all options after new(), by name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1671 | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1672 | # This allows direct addressing by name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1673 | 3203 | ▶ | local $^W = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=10 SCAR=26.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1674 | 3203 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1675 | 3203 | my($name) = $AUTOLOAD =~ /.*::(.+)/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1676 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1677 | # If fieldsubs => 1 set, then allow grabbing fields directly | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1678 | 3203 | ▶ | if ($self->{fieldsubs} && $self->{fieldrefs}{$name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"fieldsubs"} and $self->{"fieldrefs"}{$name}
MC/DC0%0/2
$self->{"fieldsubs"} and $self->{"fieldrefs"}{$name}
$self->{"fieldsubs"}
$self->{"fieldrefs"}{$name}
Truth table33%1/3
A and B
A= $self->{"fieldsubs"}B= $self->{"fieldrefs"}{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1679 | 0 | return $self->field(name => $name, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1680 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1681 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1682 | 3203 | debug 3, "-> dispatch to \$form->{$name} = @_"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1683 | 3203 | ▶ | if (@_ % 2 == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1684 | 5 | $self->{$name} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1685 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1686 | 5 | ▶ | if ($REARRANGE{$name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1687 | # needs to be splatted into every field | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1688 | 2 | for ($self->fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1689 | 6 | my $tval = rearrange($self->{$name}, "$_"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1690 | 6 | $_->$name($tval); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1691 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1692 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1693 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1694 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1695 | # Try to catch $form->$fieldname usage | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1696 | 3203 | ▶ | if ((! exists($self->{$name}) || @_) && ! $CGI::FormBuilder::Util::OURATTR{$name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
!exists $self->{$name} || @_ and not $CGI::FormBuilder::Util::OURATTR{$name}
not exists $self->{$name} or @_
MC/DC0%0/3
!exists $self->{$name} || @_ and not $CGI::FormBuilder::Util::OURATTR{$name}
not exists $self->{$name}
@_
not $CGI::FormBuilder::Util::OURATTR{$name}
Truth table40%2/5
not(A) or B and not(C)
A= not exists $self->{$name}B= @_C= not $CGI::FormBuilder::Util::OURATTR{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1697 | 0 | ▶ | if ($self->{fieldsubs}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1698 | 0 | return $self->field(name => $name, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1699 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1700 | 0 | belch "Possible field access via \$form->$name() - see 'fieldsubs' option" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1701 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1702 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1703 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1704 | 3203 | return $self->{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1705 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1706 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1707 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1708 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||