blib/lib/DBIx/POS.pm

filter: Statementstmt 68.2% 58 / 85 Branchbran 38.8% 14 / 36 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 65.0% 13 / 20 Podpod 0.0% 0 / 5 totaltotal 56.4% 87 / 154 CC 21 SCAR 17.0
CC
21
Cov
59%
verbatim
20.0
desc
6.0
name
6.0
CRAP 5.5
↑ Summary
1 package DBIx::POS::Statement;
2  
3 1 ▶use overload '""' => sub { shift->{sql} };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
4  
5 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
6 1 my $proto = shift;
7 1 ▶ my $class = ref $proto || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
8 1 my $self = shift;
9 1 bless ($self, $class);
10 1 return $self;
11 }
12  
13 0 ▶sub desc {
Subroutine desc: not called CC=2 SCAR=17.9
14 0 my $self = shift;
15 0 ▶ $self->{desc} = shift if (@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
16 0 return $self->{desc};
17 }
18  
19 0 ▶sub name {
Subroutine name: not called CC=2 SCAR=17.9
20 0 my $self = shift;
21 0 ▶ $self->{name} = shift if (@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
22 0 return $self->{name};
23 }
24  
25 0 ▶sub noreturn {
Subroutine noreturn: not called CC=2 SCAR=17.9
26 0 my $self = shift;
27 0 ▶ $self->{noreturn} = shift if (@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
28 0 return $self->{noreturn};
29 }
30  
31 0 ▶sub param {
Subroutine param: not called CC=2 SCAR=17.9
32 0 my $self = shift;
33 0 ▶ $self->{param} = shift if (@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
34 0 return $self->{param};
35 }
36  
37 0 ▶sub short {
Subroutine short: not called CC=2 SCAR=17.9
38 0 my $self = shift;
39 0 ▶ $self->{short} = shift if (@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
40 0 return $self->{short};
41 }
42  
43 0 ▶sub sql {
Subroutine sql: not called CC=2 SCAR=17.9
44 0 my $self = shift;
45 0 ▶ $self->{sql} = shift if (@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
46 0 return $self->{sql};
47 }
48  
49 package DBIx::POS;
50 # arch-tag: 2f764256-6fc0-415e-865d-767d9f202f02
51  
52 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 1 ▶use base qw{Pod::Parser};
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 # Set our version
57 1 our $VERSION = '0.03';
58  
59 # Hold data for our pending statement
60 1 my $info = {};
61  
62 # Hold our SQL
63 1 my %sql;
64  
65 # What command we're looking at
66 my $state;
67  
68 # Does the work of creating a new instance
69 1 ▶sub _new_instance {
Subroutine _new_instance: called CC=1 SCAR=0.0
70 1 my $class = shift;
71 1 my $file = shift;
72 1 $class->new->parse_from_file ($file);
73 1 bless \%sql, $class;
74 }
75  
76 # Handle =whatever commands
77 4 ▶sub command {
Subroutine command: called CC=5 SCAR=16.3
Pod undocumented
78 4 my ($self, $command, $paragraph, $line) = @_;
79  
80 # Get rid of all trailing whitespace
81 4 $paragraph =~ s/\s+$//ms;
82  
83 # There may be a short description right after the command
84 4 ▶ if ($command eq 'desc') {
Branch: 1 branch
BranchTrueFalseTotal
if ($command eq "desc") 1 3 4
85 1 ▶ $info->{short} = $paragraph || "";
Condition50%1/2
$paragraph || ''
l!l
10
MC/DC0%0/1
$paragraph || ''
$paragraph
Truth table50%1/2
A
A= $paragraph
Aresult
11
00
86 }
87  
88 # The name comes right after the command
89 4 ▶ if ($command eq 'name') {
Branch: 1 branch
BranchTrueFalseTotal
if ($command eq "name") 1 3 4
90 1 $self->end_input;
91 1 $info->{name} = $paragraph;
92 }
93  
94 # The noreturn comes right after the command
95 4 ▶ if ($command eq 'noreturn') {
Branch: 1 branch
BranchTrueFalseTotal
if ($command eq "noreturn") 0 4 4
96 0 $info->{noreturn} = 1;
97 }
98  
99 # Remember what command we're in
100 4 $state = $command;
101 }
102  
103 2 ▶sub end_input {
Subroutine end_input: called CC=3 SCAR=11.0
Pod undocumented
104 2 my ($self) = @_;
105  
106 # If there's stuff to try and construct from
107 2 ▶ if (%{$info}) {
Branch: 1 branch
BranchTrueFalseTotal
if (%{$info;}) 1 1 2
108  
109 # If we have the necessary bits
110 1 ▶ if (scalar (grep {m/^(?:name|short|desc|sql)$/} keys %{$info}) == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar grep({/^(?:name|short|desc|sql)$/;} keys %{$info;}) == 3) { } 1 0 1
111  
112 # Grab the entire content for the %sql hash
113 1 $sql{$info->{name}} = DBIx::POS::Statement->new ($info);
114  
115 # Start with a new empty hashref
116 1 $info = {};
117 }
118  
119 # Something's missing
120 else {
121  
122 # A nice format for dumping
123 1 ▶ use YAML qw{Dump};
Subroutine BEGIN: called CC=1 SCAR=0.0
124  
125 0 die "Malformed entry\n" . Dump (\%sql, $info);
126 }
127 }
128 }
129  
130 # Taken directly from Class::Singleton---we were already overriding
131 # _new_instance, and it seemed silly to have an additional dependency
132 # for four statements.
133  
134 2 ▶sub instance {
Subroutine instance: called CC=2 SCAR=6.9
Pod undocumented
135 2 my $class = shift;
136  
137 # get a reference to the _instance variable in the $class package
138 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
139 2 my $instance = \${ "$class\::_instance" };
140  
141 2 ▶ defined $$instance
Branch: 1 branch
BranchTrueFalseTotal
defined $$instance ? : 1 1 2
142 ? $$instance
143 : ($$instance = $class->_new_instance(@_));
144 }
145  
146 # Handle the blocks of text between commands
147 2 ▶sub textblock {
Subroutine textblock: called CC=4 SCAR=14.5
Pod undocumented
148 2 my ($parser, $paragraph, $line) = @_;
149  
150 # Collapse trailing whitespace to a \n
151 2 $paragraph =~ s/\s+$/\n/ms;
152  
153 2 ▶ if ($state eq 'desc') {
Branch: 3 branches
BranchTrueFalseTotal
if ($state eq 'desc') { } 0 2 2
elsif ($state eq 'param') { } 1 1 2
elsif ($state eq 'sql') { } 1 0 1
154 0 $info->{desc} .= $paragraph;
155 }
156  
157 elsif ($state eq 'param') {
158 1 $info->{param} .= $paragraph;
159 }
160  
161 elsif ($state eq 'sql') {
162 1 $info->{sql} .= $paragraph;
163 }
164 }
165  
166 # We handle verbatim sections the same way
167 0 ▶sub verbatim {
Subroutine verbatim: not called CC=4 SCAR=30.0
Pod undocumented
168 0 my ($parser, $paragraph, $line) = @_;
169  
170 # Collapse trailing whitespace to a \n
171 0 $paragraph =~ s/\s+$/\n/ms;
172  
173 0 ▶ if ($state eq 'desc') {
Branch: 3 branches
BranchTrueFalseTotal
if ($state eq 'desc') { } 0 0 0
elsif ($state eq 'param') { } 0 0 0
elsif ($state eq 'sql') { } 0 0 0
174 0 $info->{desc} .= $paragraph;
175 }
176  
177 elsif ($state eq 'param') {
178 0 $info->{param} .= $paragraph;
179 }
180  
181 elsif ($state eq 'sql') {
182 0 $info->{sql} .= $paragraph;
183 }
184 }
185  
186 1 1;
187  
188 __END__
↑ Summary