blib/lib/MonetDB/CLI/MapiPP.pm

filter: Statementstmt 15.8% 17 / 107 Branchbran 1.6% 1 / 60 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 23.8% 5 / 21 Podpod 0.0% 0 / 2 totaltotal 10.7% 23 / 214 CC 40 SCAR 57.4
CC
40
Cov
10%
query
702.0
unquote
30.0
connect
17.8
CRAP 309.9
↑ Summary
1 package MonetDB::CLI::MapiPP;
2  
3 3 ▶use IO::Socket::INET();
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Text::ParseWords();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 our $VERSION = '0.03';
9  
10  
11 3 my %unescape = ( n => "\n", t => "\t", r => "\r", f => "\f");
12  
13 sub unquote
14 0 ▶{
Subroutine unquote: not called CC=5 SCAR=34.0
Pod undocumented
15 0 my ($class, $v) = @_;
16  
17 0 ▶ return undef if $v eq 'NULL' || $v eq 'nil';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "NULL" or $v eq "nil" 0 0 0
Condition0%0/3
$v eq "NULL" or $v eq "nil"
l!l&&r!l&&!r
000
MC/DC0%0/2
$v eq "NULL" or $v eq "nil"
$v eq "NULL" $v eq "nil"
Truth table0%0/3
A or B
A= $v eq "NULL"B= $v eq "nil"
ABresult
1X1
011
000
18  
19 0 ▶ if ( $v =~ /^["']/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /^["']/) 0 0 0
20 0 $v =~ s/^["']//;
21 0 $v =~ s/["']$//;
22 0 ▶ $v =~ s/\\(.)/$unescape{$1}||$1/eg;
Condition0%0/3
$unescape{$1} || $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$unescape{$1} || $1
$unescape{$1} $1
Truth table0%0/3
A || B
A= $unescape{$1}B= $1
ABresult
1X1
011
000
23 }
24 0 return $v;
25 }
26  
27  
28 sub connect
29 2 ▶{
Subroutine connect: called CC=5 SCAR=28.8
Pod undocumented
30 2 my ($class, $host, $port, $user, $pass, $lang) = @_;
31  
32 2 ▶ my $h = IO::Socket::INET->new( PeerAddr => $host, PeerPort => $port )
Branch: 1 branch
BranchTrueFalseTotal
my $h = "IO::Socket::INET"->new("PeerAddr", $host, "PeerPort", $port) or die "Handle is undefined: $@" 0 2 2
33 or die "Handle is undefined: $@";
34 0 <$h>;
35 0 ▶ print $h "$user:$pass:$lang:line\n" or die $!;
Branch: 1 branch
BranchTrueFalseTotal
print $h "${user}:${pass}:${lang}:line\n" or die $! 0 0 0
36 0 ▶ while ( local $_ = <$h> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(local $_ = readline $h)) 0 0 0
37 0 ▶ last if /^\001/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\001/ 0 0 0
38 }
39 0 bless { h => $h, lang => $lang },'MonetDB::CLI::MapiPP::Cxn';
40 }
41  
42  
43 package MonetDB::CLI::MapiPP::Cxn;
44  
45 sub query
46 0 ▶{
Subroutine query: not called CC=1 SCAR=6.9
47 0 my ($self, $statement) = @_;
48  
49 0 my $h = $self->new_handle;
50 0 $h->query( $statement );
51  
52 0 return $h;
53 }
54  
55 sub new_handle
56 0 ▶{
Subroutine new_handle: not called CC=1 SCAR=6.9
57 0 my ($self) = @_;
58  
59 0 bless { p => $self },'MonetDB::CLI::MapiPP::Req';
60 }
61  
62 sub DESTROY
63 0 ▶{
Subroutine DESTROY: not called CC=1 SCAR=6.9
64 0 my ($self) = @_;
65  
66 0 $self->{h}->close;
67  
68 0 return;
69 }
70  
71  
72 package MonetDB::CLI::MapiPP::Req;
73  
74 sub query
75 0 ▶{
Subroutine query: not called CC=26 SCAR=65.5
76 0 my ($self, $statement) = @_;
77  
78 0 my $lang = $self->{p}{lang};
79 0 my $h = $self->{p}{h};
80 0 ▶ my $delim = $lang eq 'sql' ? qr(\s*,\s*) : qr(\s+);
Branch: 1 branch
BranchTrueFalseTotal
$lang eq 'sql' ? : 0 0 0
81 0 my @err;
82  
83 0 ▶ if ( $lang eq 'sql') {
Branch: 1 branch
BranchTrueFalseTotal
if ($lang eq 'sql') { } 0 0 0
84 0 my @statement = split /\n/, $statement;
85 0 s/--.*// for @statement; # TODO: -- inside '' (or blocked mode?)
86 0 $statement = join ' ', @statement;
87 0 ▶ $statement .= ';' unless $statement =~ /;$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $statement =~ /;$/ 0 0 0
88 0 $statement = 's' . $statement;
89 }
90 else {
91 0 $statement =~ s/\n/ /g;
92 }
93 0 ▶ print $h $statement,"\n" or die $!;
Branch: 1 branch
BranchTrueFalseTotal
print $h $statement, "\n" or die $! 0 0 0
94  
95 0 $self->finish;
96  
97 0 ▶ while ( local $_ = <$h> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(local $_ = readline $h)) 0 0 0
98 0 chomp;
99 0 ▶ if (/^\[/) {
Branch: 7 branches
BranchTrueFalseTotal
if (/^\[/) { } 0 0 0
elsif (/^&(\d) (\d+) (\d+) (\d+)/) { } 0 0 0
elsif (/^&(\d) (\d+)/) { } 0 0 0
elsif (/^#\s+\b(.*)\b\s+# (name|type|length)$/) { } 0 0 0
elsif (/^!/) { } 0 0 0
elsif (/^\001\001/) { } 0 0 0
elsif (/^\001\002/) { } 0 0 0
100 0 ▶ die "Incomplete tuple: $_" unless /\]$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\]$/ 0 0 0
101 0 s/^\[\s*//;
102 0 s/\s*\]$//;
103 0 my @a = Text::ParseWords::parse_line( qr(\s*,\s*), 0, $_ );
104 0 push @{$self->{rs}}, [ map { MonetDB::CLI::MapiPP->unquote( $_ ) } @a ];
105 }
106 elsif (/^&(\d) (\d+) (\d+) (\d+)/) {
107 0 ▶ $self->{querytype} = $1 if $self->{querytype} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"querytype"} < 0 0 0 0
108 0 ▶ $self->{id} = $2 if $self->{id} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"id"} < 0 0 0 0
109 0 ▶ $self->{tuplecount} = $3 if $self->{tuplecount} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tuplecount"} < 0 0 0 0
110 0 ▶ $self->{columncount} = $4 if $self->{columncount} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"columncount"} < 0 0 0 0
111 }
112 elsif (/^&(\d) (\d+)/) {
113 0 ▶ $self->{querytype} = $1 if $self->{querytype} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"querytype"} < 0 0 0 0
114 0 ▶ $self->{tuplecount} = $2 if $self->{tuplecount} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tuplecount"} < 0 0 0 0
115 }
116 elsif (/^#\s+\b(.*)\b\s+# (name|type|length)$/) {
117 0 $self->{$2} = [ split $delim, $1 ];
118 }
119 elsif (/^!/) {
120 0 push @err, $_;
121 }
122 elsif (/^\001\001/) {
123 0 last;
124 }
125 elsif (/^\001\002/) {
126 0 die "Incomplete query: $statement";
127 }
128 }
129 0 ▶ $self->{columncount} = @{$self->{name}} if $self->{columncount} < 0;;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"columncount"} < 0 0 0 0
130 0 ▶ $self->{columncount} ||= @{$self->{rs}[0]} if $self->{rs}[0];
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"rs"}[0] 0 0 0
Condition0%0/3
$self->{"columncount"} ||= @{$self->{"rs"}[0];}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"columncount"} ||= @{$self->{"rs"}[0];}
$self->{"columncount"} @{$self->{"rs"}[0];}
Truth table0%0/3
A ||= B
A= $self->{"columncount"}B= @{$self->{"rs"}[0];}
ABresult
1X1
011
000
131 0 ▶ $self->{tuplecount} = @{$self->{rs}} if $lang ne 'sql';
Branch: 1 branch
BranchTrueFalseTotal
if $lang ne "sql" 0 0 0
132  
133 0 ▶ die join "\n", @err if @err;
Branch: 1 branch
BranchTrueFalseTotal
if @err 0 0 0
134  
135 0 return;
136 }
137  
138 sub querytype
139 0 ▶{
Subroutine querytype: not called CC=1 SCAR=6.9
140 0 my ($self) = @_;
141  
142 0 return $self->{querytype};
143 }
144  
145 sub id
146 0 ▶{
Subroutine id: not called CC=1 SCAR=6.9
147 0 my ($self) = @_;
148  
149 0 return $self->{id};
150 }
151  
152 sub rows_affected
153 0 ▶{
Subroutine rows_affected: not called CC=1 SCAR=6.9
154 0 my ($self) = @_;
155  
156 0 return $self->{tuplecount};
157 }
158  
159 sub columncount
160 0 ▶{
Subroutine columncount: not called CC=1 SCAR=6.9
161 0 my ($self) = @_;
162  
163 0 return $self->{columncount};
164 }
165  
166 sub name
167 0 ▶{
Subroutine name: not called CC=2 SCAR=17.9
168 0 my ($self, $fnr) = @_;
169  
170 0 ▶ return $self->{name}[$fnr] || '';
Condition0%0/2
$self->{'name'}[$fnr] || ''
l!l
00
MC/DC0%0/1
$self->{'name'}[$fnr] || ''
$self->{'name'}[$fnr]
Truth table0%0/2
A
A= $self->{'name'}[$fnr]
Aresult
11
00
171 }
172  
173 sub type
174 0 ▶{
Subroutine type: not called CC=2 SCAR=17.9
175 0 my ($self, $fnr) = @_;
176  
177 0 ▶ return $self->{type}[$fnr] || '';
Condition0%0/2
$self->{'type'}[$fnr] || ''
l!l
00
MC/DC0%0/1
$self->{'type'}[$fnr] || ''
$self->{'type'}[$fnr]
Truth table0%0/2
A
A= $self->{'type'}[$fnr]
Aresult
11
00
178 }
179  
180 sub length
181 0 ▶{
Subroutine length: not called CC=2 SCAR=17.9
182 0 my ($self, $fnr) = @_;
183  
184 0 ▶ return $self->{length}[$fnr] || 0;
Condition0%0/2
$self->{'length'}[$fnr] || 0
l!l
00
MC/DC0%0/1
$self->{'length'}[$fnr] || 0
$self->{'length'}[$fnr]
Truth table0%0/2
A
A= $self->{'length'}[$fnr]
Aresult
11
00
185 }
186  
187 sub fetch
188 0 ▶{
Subroutine fetch: not called CC=2 SCAR=17.9
189 0 my ($self) = @_;
190  
191 0 ▶ return if ++$self->{i} > $#{$self->{rs}};
Branch: 1 branch
BranchTrueFalseTotal
if ++$self->{"i"} > $#{$$self{"rs"};} 0 0 0
192 0 return $self->{columncount};
193 }
194  
195 sub field
196 0 ▶{
Subroutine field: not called CC=1 SCAR=6.9
197 0 my ($self, $fnr) = @_;
198  
199 0 return $self->{rs}[$self->{i}][$fnr];
200 }
201  
202 sub finish
203 0 ▶{
Subroutine finish: not called CC=3 SCAR=24.8
204 0 my ($self) = @_;
205  
206 0 $self->{$_} = -1 for qw(querytype id tuplecount columncount i);
207 0 $self->{$_} = [] for qw(rs name type length);
208  
209 0 return;
210 }
211  
212 sub DESTROY
213 0 ▶{
Subroutine DESTROY: not called CC=1 SCAR=6.9
214 0 my ($self) = @_;
215  
216 0 return;
217 }
218  
219 3 __PACKAGE__;
220  
221 =head1 NAME
222  
223 MonetDB::CLI::MapiPP - MonetDB::CLI implementation, using the Mapi protocol
224  
225 =head1 DESCRIPTION
226  
227 MonetDB::CLI::MapiPP is an implementation of the MonetDB call level interface
228 L<MonetDB::CLI>.
229 It's a Pure Perl module.
230 It uses the Mapi protocol - a text based communication layer on top of TCP.
231 Normally, you don't use this module directly, but let L<MonetDB::CLI>
232 choose an implementation module.
233  
234 =head1 AUTHORS
235  
236 Steffen Goeldner E<lt>sgoeldner@cpan.orgE<gt>.
237  
238 =head1 COPYRIGHT AND LICENCE
239  
240 The contents of this file are subject to the MonetDB Public License
241 Version 1.1 (the "License"); you may not use this file except in
242 compliance with the License. You may obtain a copy of the License at
243 http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
244  
245 Software distributed under the License is distributed on an "AS IS"
246 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
247 License for the specific language governing rights and limitations
248 under the License.
249  
250 The Original Code is the MonetDB Database System.
251  
252 The Initial Developer of the Original Code is CWI.
253 Portions created by CWI are Copyright (C) 1997-2006 CWI.
254 All Rights Reserved.
255  
256 =head1 SEE ALSO
257  
258 =head2 MonetDB
259  
260 Homepage : http://monetdb.cwi.nl
261 SourceForge : http://sourceforge.net/projects/monetdb
262  
263 =head2 Perl modules
264  
265 L<MonetDB::CLI>
266  
267 =cut
↑ Summary