blib/lib/Data/Stag/ITextParser.pm

filter: Statementstmt 86.9% 60 / 69 Branchbran 55.0% 11 / 20 Conditioncond 66.6% 6 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 3 totaltotal 75.8% 88 / 116 CC 14 SCAR 22.1
CC
14
Cov
79%
parse_fh
16.0
pop_to_level
4.0
fmtstr
2.0
CRAP 9.1
« blib/lib/Data/Stag/BaseHandler.pm ↑ Summary blib/lib/Data/Stag/JSONWriter.pm »
1 # $Id: ITextParser.pm,v 1.19 2008/06/03 17:31:15 cmungall Exp $
2 #
3 # Copyright (C) 2002 Chris Mungall <cjm@fruitfly.org>
4 #
5 # See also - http://stag.sourceforge.net
6 #
7 # This module is free software.
8 # You may distribute this module under the same terms as perl itself
9  
10 package Data::Stag::ITextParser;
11  
12 =head1 NAME
13  
14 ITextParser.pm - parses stag IText format into stag events
15  
16 =head1 SYNOPSIS
17  
18 =cut
19  
20 =head1 DESCRIPTION
21  
22  
23 =head1 AUTHOR
24  
25 =cut
26  
27 8 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 8 ▶use FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 8 ▶use base qw(Data::Stag::BaseGenerator Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 8 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
34 8 $VERSION="0.14";
35  
36 0 ▶sub fmtstr {
Subroutine fmtstr: not called CC=1 SCAR=6.9
Pod undocumented
37 0 return 'itext';
38 }
39  
40 10 ▶sub parse_fh {
Subroutine parse_fh: called CC=11 SCAR=27.7
Pod undocumented
41 10 my $self = shift;
42 10 my $fh = shift;
43 10 my @stack = ();
44 10 my $txt;
45  
46 10 ▶ while(<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 370 10 380
47 370 chomp;
48 370 s/\\\#/MAGIC_WORD_HASH/g;
49 370 s/\#.*//;
50 370 s/MAGIC_WORD_HASH/\#/g;
51 370 ▶ next unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 370 370
52  
53 # remove trailing ws
54 370 s/\s*$//;
55  
56 370 my $eofre = '\<\<(\S+)' . "\$";
57 370 ▶ if (/$eofre/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/$eofre/) 0 370 370
58 0 my $eof = $1;
59 0 s/$eofre//;
60 0 my $sofar = $_;
61 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
62 0 ▶ last if /^$eof/;
Branch: 1 branch
BranchTrueFalseTotal
if /^$eof/ 0 0 0
63 0 $sofar .= $_;
64 }
65 0 $_ = $sofar;
66 }
67  
68 # get indent level
69 370 /(\s*)(.*)/s;
70  
71 370 my ($indent_txt, $elt) = ($1, $2);
72 370 my $indent = length($indent_txt);
73 370 ▶ if ($elt =~ /^([\w\-\+\?\*]+):\s*(.*)$/s ||
Branch: 1 branch
BranchTrueFalseTotal
if ($elt =~ /^([\w\-\+\?\*]+):\s*(.*)$/s or $elt =~ /^([\@\.]):\s*(.*)$/s) { } 370 0 370
Condition33%1/3
$elt =~ /^([\w\-\+\?\*]+):\s*(.*)$/s or $elt =~ /^([\@\.]):\s*(.*)$/s
l!l&&r!l&&!r
37000
MC/DC0%0/2
$elt =~ /^([\w\-\+\?\*]+):\s*(.*)$/s or $elt =~ /^([\@\.]):\s*(.*)$/s
$elt =~ /^([\w\-\+\?\*]+):\s*(.*)$/s $elt =~ /^([\@\.]):\s*(.*)$/s
Truth table33%1/3
A or B
A= $elt =~ /^([\w\-\+\?\*]+):\s*(.*)$/sB= $elt =~ /^([\@\.]):\s*(.*)$/s
ABresult
1X1
011
000
74 $elt =~ /^([\@\.]):\s*(.*)$/s) {
75 370 $elt = $1;
76 370 my $nu_txt = $2;
77  
78 370 $self->pop_to_level($indent, $txt, \@stack);
79 370 $txt = undef;
80 370 ▶ if ($nu_txt || length($nu_txt)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nu_txt or length $nu_txt) 240 130 370
Condition66%2/3
$nu_txt or length $nu_txt
l!l&&r!l&&!r
2400130
MC/DC50%1/2
$nu_txt or length $nu_txt
$nu_txt length $nu_txt
Truth table66%2/3
A or B
A= $nu_txtB= length $nu_txt
ABresult
1X1
011
000
81 240 $txt = $nu_txt;
82 }
83 370 $self->start_event($elt);
84 370 push(@stack, [$indent, $elt]);
85 }
86 else {
87 # body
88 0 ▶ $txt .= $elt if $elt;
Branch: 1 branch
BranchTrueFalseTotal
if $elt 0 0 0
89 }
90 }
91 10 $fh->close;
92 10 $self->pop_to_level(0, $txt, \@stack);
93 10 return;
94 }
95  
96 380 ▶sub pop_to_level {
Subroutine pop_to_level: called CC=4 SCAR=13.9
Pod undocumented
97 380 my $self = shift;
98 380 my $indent = shift;
99 380 my $txt = shift;
100 380 my $stack = shift;
101  
102 # if buffered pcdata, export it
103 380 ▶ if (defined $txt) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $txt) 240 140 380
104 # unescape :s
105 240 $txt =~ s/^\\:/:/g;
106 240 $txt =~ s/([^\\])\\:/$1:/g;
107 240 $self->evbody($txt);
108 }
109 380 ▶ while (scalar(@$stack) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$stack and $stack->[-1][0] >= $indent) 370 380 750
Condition100%3/3
scalar @$stack and $stack->[-1][0] >= $indent
!ll&&!rl&&r
20360370
MC/DC100%2/2
scalar @$stack and $stack->[-1][0] >= $indent
scalar @$stack $stack->[-1][0] >= $indent
Truth table100%3/3
A and B
A= scalar @$stackB= $stack->[-1][0] >= $indent
ABresult
0X0
100
111
110 $stack->[-1]->[0] >= $indent) {
111 370 $self->end_event($stack->[-1]->[1]);
112 370 pop(@$stack);
113 }
114 380 return;
115 }
116  
117 8 1;
« blib/lib/Data/Stag/BaseHandler.pm ↑ Summary blib/lib/Data/Stag/JSONWriter.pm »