| 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 | package CGI::FormBuilder::Source::File; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | CGI::FormBuilder::Source::File - Initialize FormBuilder from external file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # use the main module | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | use CGI::FormBuilder; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | my $form = CGI::FormBuilder->new(source => 'form.conf'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | my $lname = $form->field('lname'); # like normal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | use 5.006; # or later | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | use CGI::FormBuilder::Util; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | our $VERSION = '3.10'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # Begin "real" code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 23 | ▶ | my $mod = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 23 | ▶ | my $class = ref($mod) || $mod; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $mod || $mod
MC/DC0%0/2
ref $mod || $mod
ref $mod
$mod
Truth table33%1/3
A || B
A= ref $modB= $mod
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 23 | my %opt = arghash(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 23 | return bless \%opt, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | sub parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 23 | ▶ | local $^W = 0; # -w sucks so hard | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=51 SCAR=42.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 23 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 23 | ▶ | my $file = shift || $self->{source}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() || $self->{'source'}
MC/DC0%0/2
shift() || $self->{'source'}
shift()
$self->{'source'}
Truth table33%1/3
A || B
A= shift()B= $self->{'source'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 23 | ▶ | $CGI::FormBuilder::Util::DEBUG ||= $self->{debug} if ref $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$CGI::FormBuilder::Util::DEBUG ||= $self->{"debug"}
MC/DC0%0/2
$CGI::FormBuilder::Util::DEBUG ||= $self->{"debug"}
$CGI::FormBuilder::Util::DEBUG
$self->{"debug"}
Truth table33%1/3
A ||= B
A= $CGI::FormBuilder::Util::DEBUGB= $self->{"debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 23 | my $ret = {}; # top level | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 23 | my $ptr = $ret; # curr ptr | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 23 | my @lvl = (); # previous levels | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 23 | my $s = 0; # curr spaces | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 23 | my $lsp = 0; # level spaces | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 23 | my $psp = 0; # prev spaces | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 23 | my $refield = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 23 | my @file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 23 | my $utf8 = 0; # parse file as utf8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 23 | debug 1, "parsing $file as input source"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 23 | ▶ | if (ref $file eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 23 | @file = split /[\r\n]+/, $$file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } elsif (ref $file eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | @file = @$file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | open(F, "<$file") || puke "Cannot read $file: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | @file = <F>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | close F; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 23 | my($lterm, $here); # level term, here string | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 23 | my $inval = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 23 | for (@file) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 239 | ▶ | next if /^\s*$/ || /^\s*#/; # blanks and comments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
/^\s*$/ or /^\s*#/
MC/DC100%2/2
/^\s*$/ or /^\s*#/
/^\s*$/
/^\s*#/
Truth table100%3/3
A or B
A= /^\s*$/B= /^\s*#/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 214 | ▶ | next if /^\s*\[\%\s*\#|^\s*-*\%\]/; # TT comments too | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 214 | chomp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 214 | my($term, $line) = split /\s*:\s*/, $_, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 214 | ▶ | $utf8 = 1 if $term eq 'charset' && $line =~ /^utf/; # key off charset to decode value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$term eq "charset" and $line =~ /^utf/
MC/DC0%0/2
$term eq "charset" and $line =~ /^utf/
$term eq "charset"
$line =~ /^utf/
Truth table33%1/3
A and B
A= $term eq "charset"B= $line =~ /^utf/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 214 | ▶ | $line = Encode::decode('utf-8', $line) if $utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # here string term-inator (har) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 214 | ▶ | if ($here) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | ▶ | if ($term eq $here) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | undef $here; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | $line = $term; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | $term = $lterm; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # count leading space if it's there | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 211 | $s = 1; # reset | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 211 | ▶ | $s += length($1) if $term =~ s/^(\s+)//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 211 | $line =~ s/\s+$//; # trailing space | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # uplevel pre-check (may have a value below) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 211 | ▶ | if ($s == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 91 | $ptr = $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 91 | @lvl = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 91 | $lsp = 1; # set to zero for next pass | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 91 | $refield = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 91 | $inval = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } elsif ($s <= $lsp) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 24 | ▶ | $ptr = pop(@lvl) || $ret; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
pop @lvl || $ret
MC/DC0%0/2
pop @lvl || $ret
pop @lvl
$ret
Truth table33%1/3
A || B
A= pop @lvlB= $ret
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 24 | $lsp = $s; # uplevel term indent | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 24 | $inval = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # special catch for continued (indented) line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 211 | ▶ | if ($s >= $psp && $inval && ! length $line) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$s >= $psp and $inval and not length $line
$s >= $psp and $inval
MC/DC100%3/3
$s >= $psp and $inval and not length $line
$s >= $psp
$inval
not length $line
Truth table100%4/4
A and B and not(C)
A= $s >= $pspB= $invalC= not length $line
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | $line = $term; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | $term = $lterm; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 211 | debug 2, "[$s >= $psp, inval=$inval] term=$term; line=$line"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 213 | $psp = $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # has a value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 213 | ▶ | if (length $line) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 132 | debug 2, "$term = $line ($s < $lsp)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 132 | ▶ | $lsp ||= $s; # first valid term indent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$lsp ||= $s
MC/DC0%0/2
$lsp ||= $s
$lsp
$s
Truth table33%1/3
A ||= B
A= $lspB= $s
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # <<HERE strings bypass all subsequent parsing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 132 | ▶ | if ($line =~ /^<<(.+)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | $lterm = $term; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | $here = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } elsif ($here) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 2 | $ptr->{$term} .= "$line\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 129 | my @val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 129 | ▶ | if ($term =~ /^js/ || $term =~ /^on[a-z]/ || $term eq 'messages' || $term eq 'comment') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition77%7/9
$term =~ /^js/ or $term =~ /^on[a-z]/ or $term eq "messages" or $term eq "comment"
$term =~ /^js/ or $term =~ /^on[a-z]/ or $term eq "messages"
$term =~ /^js/ or $term =~ /^on[a-z]/
MC/DC50%2/4
$term =~ /^js/ or $term =~ /^on[a-z]/ or $term eq "messages" or $term eq "comment"
$term =~ /^js/
$term =~ /^on[a-z]/
$term eq "messages"
$term eq "comment"
Truth table60%3/5
A or B or C or D
A= $term =~ /^js/B= $term =~ /^on[a-z]/C= $term eq "messages"D= $term eq "comment"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 8 | @val = $line; # verbatim | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } elsif ($line =~ s/^\\(.)//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # Reference - this is tricky. Go all the way up to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # the top to make sure, or use $self->{caller} if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # we were given a place to go. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | my $r = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | my $l = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | my @p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | ▶ | if ($self->{caller}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | @p = $self->{caller}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | ▶ | while (my $pkg = caller($l++)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 4 | push @p, $pkg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | ▶ | $line = "$r$p[-1]\::$line" unless $line =~ /::/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | debug 2, qq{eval "\@val = (\\$line)"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 2 | eval "\@val = (\\$line)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | ▶ | belch "Loading $line failed: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # split commas | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 119 | @val = split /\s*,\s*/, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # m=Male, f=Female -> [m,Male], [f,Female] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 119 | ▶ | for (my $i=0; $i < @val; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 221 | ▶ | $val[$i] = [ split /\s*=\s*/, $val[$i], 2 ] if $val[$i] =~ /=/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # only arrayref on multi values b/c FB is "smart" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 129 | ▶ | if ($ptr->{$term}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | $ptr->{$term} = (ref $ptr->{$term}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | ▶ | ? [ @{$ptr->{$term}}, @val ] : @val > 1 ? \@val : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | ref($val[0]) eq 'ARRAY' ? \@val : $val[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 128 | ▶ | $ptr->{$term} = @val > 1 ? \@val : ref($val[0]) eq 'ARRAY' ? \@val : $val[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 129 | $inval = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 81 | debug 2, "$term: new level ($s < $lsp)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # term:\n -> nest with bracket | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 81 | ▶ | if ($term eq 'fields') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 15 | $refield = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 15 | $term = 'fieldopts'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } elsif ($refield) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 41 | push @{$ret->{fields}}, $term; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 81 | ▶ | $ptr->{$term} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ptr->{$term} ||= {}
MC/DC0%0/1
$ptr->{$term} ||= {}
$ptr->{$term}
Truth table50%1/2
A
A= $ptr->{$term}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 81 | push @lvl, $ptr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 81 | $ptr = $ptr->{$term}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 81 | $lsp = $s; # reset spaces | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 81 | $inval = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 210 | $lterm = $term; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 23 | ▶ | if (ref $self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # add in any top-level options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 23 | ▶ | while (my($k,$v) = each %$self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 23 | ▶ | $ret->{$k} = $v unless exists $ret->{$k}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # in FB, this is a class (not object) for speed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 23 | $self->{data} = $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 23 | $self->{source} = $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 23 | ▶ | return wantarray ? %$ret : $ret; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | sub write_module { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_module: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | my $mod = shift || puke "Missing required Module::Name"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
shift() || &puke('Missing required Module::Name')
MC/DC0%0/2
shift() || &puke('Missing required Module::Name')
shift()
&puke('Missing required Module::Name')
Truth table0%0/3
A || B
A= shift()B= &puke('Missing required Module::Name')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | (my $out = $mod) =~ s/.+:://; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | $out .= '.pm'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | open(M, ">$out") || puke "Can't write $out: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | print M "\n# Generated ".localtime()." by ".__PACKAGE__." $VERSION\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | print M <<EOH; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # To use this, you must write a script and then use this module. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # In your script, get this form with "my \$form = $mod->new()" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | package $mod; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | use CGI::FormBuilder; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # $mod->new() calling format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | my \$self = shift if \@_ && \@_ % 2 != 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # data structure from '$self->{source}' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | EOH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | local $Data::Dumper::Varname = 'form'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | print M " my ". Data::Dumper::Dumper($self->{data}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | print M <<'EOV'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # allow overriding of individual parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | while (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | $form1->{shift()} = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # return a new form object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | return CGI::FormBuilder->new(%$form1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # End of module | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | EOV | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | close M; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | print STDERR "Wrote $out\n"; # send to stderr in case of httpd | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||