Shebangml/State.pm

filter: Statementstmt 18.6% 11 / 59 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 33.3% 3 / 9 Podpod 100% 6 / 6 totaltotal 16.9% 20 / 118 CC 20 SCAR 36.7
CC
20
Cov
11%
new
72.0
read_literal
56.0
skip_comment
20.0
CRAP 39.3
« Shebangml/FromHTML.pm ↑ Summary Shebangml/FromXML.pm »
1 package Shebangml::State;
2 1 $VERSION = v0.0.1;
3  
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Shebangml::State - input/parser state holder
11  
12 =head1 SYNOPSIS
13  
14 =cut
15  
16 =head2 new
17  
18 my $state = Shebangml::State->new($source, %opts);
19  
20 =cut
21  
22 0 ▶sub new {
Subroutine new: not called CC=8 SCAR=42.8
Pod documented
23 0 my $package = shift;
24 0 ▶ my $class = ref($package) || $package;
Condition0%0/3
ref $package || $package
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $package || $package
ref $package $package
Truth table0%0/3
A || B
A= ref $packageB= $package
ABresult
1X1
011
000
25  
26 0 ▶ my $source = (@_ % 2) ? shift(@_) : undef;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 ? : 0 0 0
27 0 my %opts = @_; # TODO if I have opts, do I need to clone them?
28  
29 0 my $self = {%opts};
30  
31 0 ▶ defined($source) or croak("no source");
Branch: 1 branch
BranchTrueFalseTotal
defined $source or croak("no source") 0 0 0
32 0 ▶ unless(ref($source)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $source) { } 0 0 0
33 0 my $filename = $source;
34 0 $source = undef;
35 0 $self->{filename} = $filename;
36 0 ▶ open($source, '<', $filename) or croak("cannot open '$filename' $!");
Branch: 1 branch
BranchTrueFalseTotal
open $source, "<", $filename or croak("cannot open '${filename}' $!") 0 0 0
37 }
38 else {
39 0 ▶ unless(defined(eval{fileno($source)})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined eval { do { fileno $source } }) 0 0 0
40 0 my $string = $$source;
41 0 $source = undef;
42 0 ▶ open($source, '<', \$string) or croak("cannot refopen string $!");
Branch: 1 branch
BranchTrueFalseTotal
open $source, "<", \$string or croak("cannot refopen string $!") 0 0 0
43 }
44 }
45  
46 0 $self->{in_fh} = $source;
47 0 bless($self, $class);
48 0 return($self);
49 } # end subroutine new definition
50 ########################################################################
51  
52 =head2 next
53  
54 Reads another line into $state->current and returns a reference to it.
55  
56 my $CL = $state->next;
57  
58 =cut
59  
60 0 ▶sub next {
Subroutine next: not called CC=2 SCAR=17.9
Pod documented
61 0 my $self = shift;
62  
63 0 ▶ defined(my $line = readline($self->{in_fh})) or return();
Branch: 1 branch
BranchTrueFalseTotal
defined(my $line = readline $self->{"in_fh"}) or return () 0 0 0
64 # return a reference to our inner buffer
65 0 return($self->{current} = \($self->{line} = $line));
66 } # end subroutine next definition
67 ########################################################################
68  
69 =head2 current
70  
71 A reference to the current line.
72  
73 =cut
74  
75 0 ▶sub current {shift(@_)->{current}}
Subroutine current: not called CC=1 SCAR=6.9
Pod documented
76 ########################################################################
77  
78 =head1 Parser Bits
79  
80 =head2 skip_comment
81  
82 $state->skip_comment;
83  
84 =cut
85  
86 0 ▶sub skip_comment {
Subroutine skip_comment: not called CC=4 SCAR=30.0
Pod documented
87 0 my $self = shift;
88  
89 0 my $CL = $self->current;
90 0 ▶ if($$CL =~ m/^\s*#{/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$CL =~ /^\s*#{/) 0 0 0
91 0 ▶ while($CL = $self->next) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CL = $self->next) 0 0 0
92 0 ▶ return if($$CL =~ m/^\s*#}/);
Branch: 1 branch
BranchTrueFalseTotal
if $$CL =~ /^\s*#}/ 0 0 0
93 }
94 }
95 } # end subroutine skip_comment definition
96 ########################################################################
97  
98 =head2 skip_whitespace
99  
100 $state->skip_whitespace;
101  
102 =cut
103  
104 0 ▶sub skip_whitespace {
Subroutine skip_whitespace: not called CC=3 SCAR=24.8
Pod documented
105 0 my $self = shift;
106  
107 0 ▶ while(my $CL = $self->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $CL = $self->next) 0 0 0
108 0 $$CL =~ s/^\s*//;
109 0 ▶ return if(length($$CL));
Branch: 1 branch
BranchTrueFalseTotal
if length $$CL 0 0 0
110 }
111 } # end subroutine skip_whitespace definition
112 ########################################################################
113  
114 =head2 read_literal
115  
116 my $string = $state->read_literal($tag, $cr);
117  
118 =cut
119  
120 0 ▶sub read_literal {
Subroutine read_literal: not called CC=7 SCAR=40.3
Pod documented
121 0 my $self = shift;
122 0 my ($tag, $cr) = @_;
123  
124 0 my $out = '';
125 0 ▶ if($cr) { # end of that line
Branch: 1 branch
BranchTrueFalseTotal
if ($cr) { } 0 0 0
126 0 $out .= "\n";
127 0 ▶ while(my $CL = $self->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $CL = $self->next) 0 0 0
128 0 ▶ if($$CL =~ s/^\s*\}\}\}(?:#([\.\w]+);)?//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$CL =~ s/^\s*\}\}\}(?:#([\.\w]+);)?//) 0 0 0
129 0 ▶ croak("$1 not $tag") if($1 and $1 ne $tag);
Branch: 1 branch
BranchTrueFalseTotal
if $1 and $1 ne $tag 0 0 0
Condition0%0/3
$1 and $1 ne $tag
!ll&&!rl&&r
000
MC/DC0%0/2
$1 and $1 ne $tag
$1 $1 ne $tag
Truth table0%0/3
A and B
A= $1B= $1 ne $tag
ABresult
0X0
100
111
130 0 return($out);
131 }
132 0 $out .= $$CL;
133 }
134 0 die "ASSERT: no fall-through case";
135 }
136 else {
137 0 my $CL = $self->current;
138  
139 0 ▶ $$CL =~ s/(.*?)}}}// or croak("no end on $tag");
Branch: 1 branch
BranchTrueFalseTotal
$$CL =~ s/(.*?)}}}// or croak("no end on $tag") 0 0 0
140 0 $out .= $1;
141 0 return($out);
142 }
143  
144 0 die "ASSERT: no fall-through case";
145 } # end subroutine read_literal definition
146 ########################################################################
147  
148 =head1 AUTHOR
149  
150 Eric Wilhelm @ <ewilhelm at cpan dot org>
151  
152 http://scratchcomputing.com/
153  
154 =head1 BUGS
155  
156 If you found this module on CPAN, please report any bugs or feature
157 requests through the web interface at L<http://rt.cpan.org>. I will be
158 notified, and then you'll automatically be notified of progress on your
159 bug as I make changes.
160  
161 If you pulled this development version from my /svn/, please contact me
162 directly.
163  
164 =head1 COPYRIGHT
165  
166 Copyright (C) 2008 Eric L. Wilhelm, All Rights Reserved.
167  
168 =head1 NO WARRANTY
169  
170 Absolutely, positively NO WARRANTY, neither express or implied, is
171 offered with this software. You use this software at your own risk. In
172 case of loss, no person or entity owes you anything whatsoever. You
173 have been warned.
174  
175 =head1 LICENSE
176  
177 This program is free software; you can redistribute it and/or modify it
178 under the same terms as Perl itself.
179  
180 =cut
181  
182 # vi:ts=2:sw=2:et:sta
183 1 1;
« Shebangml/FromHTML.pm ↑ Summary Shebangml/FromXML.pm »