Statement/RAM.pm

filter: Statementstmt 97.3% 73 / 75 Branchbran 81.2% 13 / 16 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 94.1% 16 / 17 Podpod n/a totaltotal 92.9% 105 / 113 CC 10 SCAR 9.5
CC
10
Cov
94%
seek
6.0
fetch_row
3.0
update_current_row
2.0
CRAP 2.6
« Dialects/Role.pm ↑ Summary Dialects/AnyData.pm »
1 ############################
2 package SQL::Statement::RAM;
3 ############################
4  
5 ######################################################################
6 #
7 # This module is copyright (c), 2001,2005 by Jeff Zucker.
8 # This module is copyright (c), 2007-2020 by Jens Rehsack.
9 # All rights reserved.
10 #
11 # It may be freely distributed under the same terms as Perl itself.
12 # See below for help and copyright information (search for SYNOPSIS).
13 #
14 ######################################################################
15  
16 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 16 ▶use warnings FATAL => "all";
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 16 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 16 $VERSION = '1.414';
21  
22 ####################################
23 package SQL::Statement::RAM::Table;
24 ####################################
25  
26 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 16 ▶use warnings FATAL => "all";
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 16 ▶use SQL::Eval ();
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 16 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 16 @ISA = qw(SQL::Eval::Table);
33  
34 16 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 sub new
37 38 ▶{
Subroutine new: called CC=1 SCAR=0.0
38 38 my ( $class, $tname, $col_names, $data_tbl ) = @_;
39 38 my %table = (
40 NAME => $tname,
41 index => 0,
42 records => $data_tbl,
43 col_names => $col_names,
44 capabilities => {
45 inplace_update => 1,
46 inplace_delete => 1,
47 },
48 );
49 38 my $self = $class->SUPER::new( \%table );
50 }
51  
52 ##################################
53 # fetch_row()
54 ##################################
55 sub fetch_row
56 9155 ▶{
Subroutine fetch_row: called CC=3 SCAR=11.0
57 9155 my ( $self, $data ) = @_;
58  
59 return $self->{row} =
60 9155 ( $self->{records} and ( $self->{index} < scalar( @{ $self->{records} } ) ) )
61 9155 ▶ ? [ @{ $self->{records}->[ $self->{index}++ ] } ]
Branch: 1 branch
BranchTrueFalseTotal
$self->{'records'} && $self->{'index'} < scalar @{$self->{'records'};} ? : 8966 189 9155
Condition66%2/3
$self->{"records"} and $self->{"index"} < scalar @{$self->{"records"};}
!ll&&!rl&&r
01898966
MC/DC50%1/2
$self->{"records"} and $self->{"index"} < scalar @{$self->{"records"};}
$self->{"records"} $self->{"index"} < scalar @{$self->{"records"};}
Truth table66%2/3
A and B
A= $self->{"records"}B= $self->{"index"} < scalar @{$self->{"records"};}
ABresult
0X0
100
111
62 : undef;
63 }
64  
65 ####################################
66 # insert_new_row()
67 ####################################
68 sub insert_new_row
69 4280 ▶{
Subroutine insert_new_row: called CC=1 SCAR=0.0
70 4280 my ( $self, $data, $fields ) = @_;
71 4280 push @{ $self->{records} }, [ @{$fields} ];
72 4280 return 1;
73 }
74  
75 ##################################
76 # delete_current_row()
77 ##################################
78 sub delete_current_row
79 10 ▶{
Subroutine delete_current_row: called CC=2 SCAR=7.0
80 10 my ( $self, $data, $fields ) = @_;
81 10 my $currentRow = $self->{index} - 1;
82 10 ▶ croak "No current row" unless ( $currentRow >= 0 );
Branch: 1 branch
BranchTrueFalseTotal
unless $currentRow >= 0 0 10 10
83 10 splice @{ $self->{records} }, $currentRow, 1;
84 10 --$self->{index};
85 10 return 1;
86 }
87  
88 ##################################
89 # update_current_row()
90 ##################################
91 sub update_current_row
92 7 ▶{
Subroutine update_current_row: called CC=2 SCAR=7.0
93 7 my ( $self, $data, $fields ) = @_;
94 7 my $currentRow = $self->{index} - 1;
95 7 ▶ croak "No current row" unless ( $currentRow >= 0 );
Branch: 1 branch
BranchTrueFalseTotal
unless $currentRow >= 0 0 7 7
96 7 $self->{records}->[$currentRow] = [ @{$fields} ];
97 7 return 1;
98 }
99  
100 ##################################
101 # truncate()
102 ##################################
103 sub truncate
104 0 ▶{
Subroutine truncate: not called CC=1 SCAR=6.9
105 0 return splice @{ $_[0]->{records} }, $_[0]->{index};
106 }
107  
108 #####################################
109 # push_names()
110 #####################################
111 sub push_names
112 35 ▶{
Subroutine push_names: called CC=1 SCAR=0.0
113 35 my ( $self, $data, $names ) = @_;
114 35 $self->{col_names} = $names;
115 35 $self->{org_col_names} = [ @{$names} ];
116 35 $self->{col_nums} = SQL::Eval::Table::_map_colnums($names);
117 }
118  
119 #####################################
120 # drop()
121 #####################################
122 sub drop
123 7 ▶{
Subroutine drop: called CC=1 SCAR=0.0
124 7 my ( $self, $data ) = @_;
125 7 my $tname = $self->{NAME};
126 7 delete $data->{Database}->{sql_ram_tables}->{$tname};
127 7 return 1;
128 }
129  
130 #####################################
131 # seek()
132 #####################################
133 sub seek
134 4478 ▶{
Subroutine seek: called CC=6 SCAR=17.9
135 4478 my ( $self, $data, $pos, $whence ) = @_;
136 4478 ▶ return unless defined $self->{records};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"records"} 0 4478 4478
137 4478 my ($currentRow) = $self->{index};
138 4478 ▶ if ( $whence == 0 )
Branch: 3 branches
BranchTrueFalseTotal
if ($whence == 0) { } 4475 3 4478
elsif ($whence == 1) { } 1 2 3
elsif ($whence == 2) { } 1 1 2
139 {
140 4475 $currentRow = $pos;
141 }
142 elsif ( $whence == 1 )
143 {
144 1 $currentRow += $pos;
145 }
146 elsif ( $whence == 2 )
147 {
148 1 $currentRow = @{ $self->{records} } + $pos;
149 }
150 else
151 {
152 1 croak $self . "->seek: Illegal whence argument ($whence)";
153 }
154 4477 ▶ if ( $currentRow < 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($currentRow < 0) 1 4476 4477
155 {
156 1 croak "Illegal row number: $currentRow";
157 }
158 4476 $self->{index} = $currentRow;
159 }
160  
161 16 1;
162  
163 =pod
164  
165 =head1 NAME
166  
167 SQL::Statement::RAM
168  
169 =head1 SYNOPSIS
170  
171 SQL::Statement::RAM
172  
173 =head1 DESCRIPTION
174  
175 This package contains support for the internally used
176 SQL::Statement::RAM::Table.
177  
178 =head1 INHERITANCE
179  
180 SQL::Statement::RAM
181  
182 SQL::Statement::RAM::Table
183 ISA SQL::Eval::Table
184  
185 =head1 SQL::Statement::RAM::Table
186  
187 =head2 METHODS
188  
189 =over 8
190  
191 =item new
192  
193 Instantiates a new C<SQL::Statement::RAM::Table> object, used for temporary
194 tables.
195  
196 CREATE TEMP TABLE foo ....
197  
198 =item fetch_row
199  
200 Fetches the next row
201  
202 =item push_row
203  
204 As fetch_row except for writing
205  
206 =item delete_current_row
207  
208 Deletes the last fetched/pushed row
209  
210 =item update_current_row
211  
212 Updates the last fetched/pushed row
213  
214 =item truncate
215  
216 Truncates the table at the current position
217  
218 =item push_names
219  
220 Set the column names of the table
221  
222 =item drop
223  
224 Discards the table
225  
226 =item seek
227  
228 Seek the row pointer
229  
230 =back
231  
232 =head2 CAPABILITIES
233  
234 This table has following capabilities:
235  
236 =over 8
237  
238 =item update_current_row
239  
240 Using provided method C<update_current_row> and capability C<inplace_update>.
241  
242 =item rowwise_update
243  
244 By providing capability C<update_current_row>.
245  
246 =item inplace_update
247  
248 By definition (appropriate flag set in constructor).
249  
250 =item delete_current_row
251  
252 Using provided method C<delete_current_row> and capability C<inplace_delete>.
253  
254 =item rowwise_delete
255  
256 By providing capability C<delete_current_row>.
257  
258 =item inplace_delete
259  
260 By definition (appropriate flag set in constructor).
261  
262 =back
263  
264 =head1 SUPPORT
265  
266 You can find documentation for this module with the perldoc command.
267  
268 perldoc SQL::Statement
269  
270 You can also look for information at:
271  
272 =over 4
273  
274 =item * RT: CPAN's request tracker
275  
276 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=SQL-Statement>
277  
278 =item * AnnoCPAN: Annotated CPAN documentation
279  
280 L<http://annocpan.org/dist/SQL-Statement>
281  
282 =item * CPAN Ratings
283  
284 L<http://cpanratings.perl.org/s/SQL-Statement>
285  
286 =item * Search CPAN
287  
288 L<http://search.cpan.org/dist/SQL-Statement/>
289  
290 =back
291  
292 =head1 AUTHOR AND COPYRIGHT
293  
294 Copyright (c) 2001,2005 by Jeff Zucker: jzuckerATcpan.org
295 Copyright (c) 2007-2020 by Jens Rehsack: rehsackATcpan.org
296  
297 All rights reserved.
298  
299 You may distribute this module under the terms of either the GNU
300 General Public License or the Artistic License, as specified in
301 the Perl README file.
302  
303 =cut
« Dialects/Role.pm ↑ Summary Dialects/AnyData.pm »