blib/lib/Embperl/Form/Control/inputjoin.pm untested

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 95 CC 3 SCAR 17.5
CC
3
Cov
0%
prepare_fdat
12.0
init_data
2.0
BEGIN
2.0
CRAP 5.8
1  
2 ###################################################################################
3 #
4 # Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de
5 # Embperl - Copyright (c) 2008-2015 Gerald Richter
6 # Embperl - Copyright (c) 2015-2023 actevy.io
7 #
8 # You may distribute under the terms of either the GNU General Public
9 # License or the Artistic License, as specified in the Perl README file.
10 #
11 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
12 # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
13 # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14 #
15 # $Id$
16 #
17 ###################################################################################
18  
19 package Embperl::Form::Control::inputjoin ;
20  
21 use strict ;
22 use base 'Embperl::Form::Control' ;
23  
24 use Embperl::Inline ;
25  
26 use vars qw{%fdat} ;
27  
28 # ------------------------------------------------------------------------------------------
29 #
30 # init_data - daten aufteilen
31 #
32  
33 sub init_data
34 {
35 my ($self, $req) = @_ ;
36
37 my $fdat = $req -> {docdata} || \%fdat ;
38 my $name = $self -> {name} ;
39 my $split = $self -> {split} || $self -> {join} ;
40 my $num = $self -> {numinputs} || 1 ;
41 my $i = 0 ;
42 my @vals = split /$split/, $fdat->{$name} ;
43 for (my $i = 0; $i < $num; $i++)
44 {
45 $fdat->{"$name-_-$i"} = $vals[$i] ;
46 }
47 }
48  
49 # ------------------------------------------------------------------------------------------
50 #
51 # prepare_fdat - daten zusammenfuehren
52 #
53  
54 sub prepare_fdat
55 {
56 my ($self, $req) = @_ ;
57
58 my $fdat = $req -> {form} || \%fdat ;
59 my $name = $self -> {name} ;
60 my $join = $self -> {join} ;
61 my $num = $self -> {numinputs} || 1 ;
62 my @vals ;
63 my $ok = 0 ;
64 for (my $i = 0; $i < $num; $i++)
65 {
66 $ok = 1 if (exists $fdat->{$name}) ;
67 push @vals, $fdat->{"$name-_-$i"} ;
68 }
69 $fdat->{$name} = join ($join, @vals) if ($ok) ;
70 }
71  
72  
73  
74 1 ;
75  
76 __EMBPERL__
77
78 [# ---------------------------------------------------------------------------
79 #
80 # show_control - output the control
81 #]
82  
83 [$ sub show_control ($self)
84  
85 my $class = $self -> {class} ;
86 my $numinputs = $self -> {numinputs} ;
87 my $size = $self -> {size} ||= 80 / ($self -> {width} || 2) / $numinputs ;
88 my $sep = $self -> {separator} || ' ' ;
89 my $i = 0 ;
90 $]
91 [$ while ($i < $numinputs) $]
92 <input type="text" class="cBase cControl [+ $class +]" name="[+ $self->{name} +]-_-[+ $i +]"
93 [$if $size $]size="[+ $size +]"[$endif$]
94 [$if $self -> {maxlength} $]maxlength="[+ $self->{maxlength} +]"[$endif$]
95 [+ do { local $escmode = 0 ; $self -> {eventattrs} } +]>[+ $i + 1 < $numinputs?$sep:'' +]
96 [- $i++ -]
97 [$endwhile$]
98 [$endsub$]
99  
100 __END__