Listman/selection.pm

filter: Statementstmt 31.8% 7 / 22 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 33.3% 2 / 6 Podpod 100% 4 / 4 totaltotal 38.2% 13 / 34 CC 3 SCAR 13.2
CC
3
Cov
29%
add_line_by_number
6.0
add_lines_by_number
6.0
new
2.0
CRAP 3.8
« Listman/exporter.pm ↑ Summary Listman/line.pm »
1 # selection.pm - this file is part of the CGI::Listman distribution
2 #
3 # CGI::Listman is Copyright (C) 2002 iScream multimédia <info@iScream.ca>
4 #
5 # This package is free software; you can redistribute it and/or
6 # modify it under the same terms as Perl itself.
7 #
8 # Author: Wolfgang Sourdeau <Wolfgang@Contre.COM>
9  
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 package CGI::Listman::selection;
13  
14 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 =pod
17  
18 =head1 NAME
19  
20 CGI::Listman::selection - managing I<CGI::Listman::line>'s in batch
21  
22 =head1 SYNOPSIS
23  
24 use CGI;
25 use CGI::Listman;
26 use CGI::Listman::selection;
27  
28 my $cgi = CGI->new ();
29 my $list_manager = CGI::Listman->new ();
30  
31 [...]
32  
33 my $selection = CGI::Listman::selection->new ();
34 foreach my $param ($cgi->param ()) {
35 if ($param =~ m/^select_([0-9].*$)/) {
36 $selection->add_line_by_number ($listman, $1);
37 }
38 }
39  
40  
41 =head1 DESCRIPTION
42  
43 A I<CGI::Listman::selection> encapsulates an array of selected lines for
44 further batch processing. This is handy for example in an administration
45 interface when the developer wants to export or erase several lines at a
46 time from the database.
47  
48 =head1 API
49  
50 =head2 new
51  
52 Creates, initializes and returns a new instance of
53 I<CGI::Listman::selection> for you to enjoy and work with.
54  
55 =over
56  
57 =item Parameters
58  
59 This method takes no parameter.
60  
61 =item Return values
62  
63 A blessed instance of I<CGI::Listman::selection>.
64  
65 =back
66  
67 =cut
68  
69 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
70 0 my $class = shift;
71  
72 0 my $self = {};
73 0 my @selection_list;
74 0 $self->{'list'} = \@selection_list;
75  
76 0 bless $self, $class;
77 }
78  
79 =pod
80  
81 =head2 add_line
82  
83 Use this method to add a I<CGI::Listman::line> to your selection.
84  
85 =over
86  
87 =item Parameters
88  
89 =over
90  
91 =item line
92  
93 A single instance of I<CGI::Listman::line> to be exported.
94  
95 =back
96  
97 =item Return values
98  
99 This method returns nothing.
100  
101 =back
102  
103 =cut
104  
105 0 ▶sub add_line {
Subroutine add_line: not called CC=1 SCAR=6.9
Pod documented
106 0 my ($self, $line) = @_;
107  
108 0 my $list_ref = $self->{'list'};
109 0 push @$list_ref, $line;
110 }
111  
112 =pod
113  
114 =head2 add_line_by_number
115  
116 This method helps you adding a line by number. The first parameter has to
117 be its contextual instance of I<CGI::Listman>. Without it, a line cannot
118 be guaranteed to be numbered since line numbers make no sense when they
119 are not part of a I<CGI::Listman>.
120  
121 =over
122  
123 =item Parameters
124  
125 =over
126  
127 =item list_manager
128  
129 An instance of I<CGI::Listman>.
130  
131 =item number
132  
133 An integer representing the I<CGI::Listman::line> you want to add to your
134 selection.
135  
136 =back
137  
138 =item Return values
139  
140 This method returns nothing.
141  
142 =back
143  
144 =cut
145  
146 0 ▶sub add_line_by_number {
Subroutine add_line_by_number: not called CC=2 SCAR=17.9
Pod documented
147 0 my ($self, $listman, $number) = @_;
148  
149 0 my $line = $listman->seek_line_by_num ($number);
150 0 ▶ croak "Line number ".$number." not found.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
151 unless (defined $line);
152 0 $self->add_line ($line);
153 }
154  
155 =pod
156  
157 =head2 add_lines_by_number
158  
159 Same as above, except that it takes a reference to an ARRAY of numbers.
160  
161 =over
162  
163 =item Parameters
164  
165 =over
166  
167 =item list_manager
168  
169 An instance of I<CGI::Listman>.
170  
171 =item numbers
172  
173 A reference to an ARRAY of integers representing the
174 I<CGI::Listman::line>'s you want to add to your selection.
175  
176 =back
177  
178 =item Return values
179  
180 This method returns nothing.
181  
182 =back
183  
184 =cut
185  
186 0 ▶sub add_lines_by_number {
Subroutine add_lines_by_number: not called CC=2 SCAR=17.9
Pod documented
187 0 my ($self, $listman, $numbers) = @_;
188  
189 0 foreach my $number (@$numbers) {
190 0 $self->add_line_by_number ($listman, $number);
191 }
192 }
193  
194 1 1;
195 __END__
« Listman/exporter.pm ↑ Summary Listman/line.pm »