CGI-AppBuilder-Form
view release on metacpan or search on metacpan
$pr - a parameter hash ref
Variables used or routines called:
CGI::AppBuilder::Message
echo_msg - echo messages
How to use:
my $ifn = 'myConfig.ini';
my ($q,$ar) = $s->get_inputs($ifn);
$self->explote_html($ar->{gi}, $ar);
Return: none
This method enables a 'x' command in your GUI definition and
processes the complex elements in the hash ref. For
instance, you have a GUI hash:
gi = { # GUI Items
rts => ['rpt_src',['DataFax Generic','Study Specific'],
'DataFax Generic'],
xtd_rts => 'radio_group',
act1 => td('Action'),
act2 => td({-colspan=>'2',-align=>'center'},
gk->{opf} . submit('a','Go') . ' ' . submit('a','Update') .
' ' . reset() ),
xcp_act => 'act1,act2',
act => submit('a','Go') . ' ' . reset(),
}
and the method will copy (xcp_act) the results (HTML text)
of $gi->{act1} and and $gi->{act2} into one. The $gi->{xcp_act}
will contains the combined string.
The 'xtd_' instructs the method to use $gi->{rts} as arguments for
the method name in $gi->{xtd_rts}.
=cut
sub explode_html {
my $s = shift;
my ($gi, $pr) = @_;
my $ar = (exists $pr->{ar}) ? $pr->{ar} : {};
my $gk = (exists $pr->{gk}) ? $pr->{gk} : {};
my $gc = (exists $pr->{gc}) ? $pr->{gc} : {};
my $db = (exists $pr->{db}) ? $pr->{db} : {};
foreach my $k (keys %$gi) {
next if ($k !~ /^x(td|cp)_(.+)/i);
my ($k1, $k2) = ($1, $2);
if ($k1 =~ /^td/i) {
my $tmp_ar = [];
if (ref($gi->{$k2}) =~ /ARRAY/) {
$tmp_ar = $gi->{$k2};
} else {
$tmp_ar = eval $gi->{$k2};
}
if ($gi->{$k} =~ /^radio_group/i) {
$gi->{$k} = radio_group(@$tmp_ar);
} elsif ($gi->{$k} =~ /^popup_menu/i) {
$gi->{$k} = popup_menu(@$tmp_ar);
} else {
$gi->{$k} = td(@$tmp_ar);
}
} else {
my $txt = "";
foreach my $i (split /,/, $gi->{$k}) {
$txt .= $gi->{$i};
}
$gi->{$k} = $txt;
}
}
$s->echo_msg($gi,5);
return;
}
=head2 explode_variable ($xr, $i, $pr)
Input variables:
$xr - a hash ref such as the elements of gi,gk,gc,gf in
GUI hash array
$i - one of gi, gk, gc and gf
$pr - a parameter hash ref containing the values for $i to be
used in $xr
Variables used or routines called:
CGI::AppBuilder::Message
echo_msg - echo messages
How to use:
my $ifn = 'myConfig.ini';
my ($q,$ar) = $s->get_inputs($ifn);
my $gi = $self->explode_variable($ar, 'gi', $ar);
my $gc = $self->explode_variable($ar, 'gc', $ar);
Return: hash or hash ref for $i.
This method replaces variable names with their values and HTML
commands with their results.
=cut
sub explode_variable {
my $s = shift;
my ($xr, $i, $pr) = @_;
my $hr = {};
return wantarray ? %$hr : $hr if ! exists $xr->{$i};
my $ar = (exists $pr->{ar}) ? $pr->{ar} : {};
my $gi = (exists $pr->{gi}) ? $pr->{gi} : {};
my $gk = (exists $pr->{gk}) ? $pr->{gk} : {};
my $gc = (exists $pr->{gc}) ? $pr->{gc} : {};
my $db = (exists $pr->{db}) ? $pr->{db} : {};
if (ref($xr->{$i}) =~ /HASH/) {
foreach my $k (keys %{$xr->{$i}}) {
if (ref($xr->{$i}{$k}) =~ /^ARRAY/) {
for my $j (0..$#{$xr->{$i}{$k}}) {
$hr->{$k}[$j] =
( run in 0.538 second using v1.01-cache-2.11-cpan-364913b4093 )