blib/lib/Data/Stag/SxprWriter.pm

filter: Statementstmt 82.4% 61 / 74 Branchbran 67.8% 19 / 28 Conditioncond 88.8% 8 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 83.3% 10 / 12 Podpod 33.3% 3 / 9 totaltotal 75.1% 103 / 137 CC 18 SCAR 14.4
CC
18
Cov
79%
evbody
7.5
o
6.0
end_event
5.3
CRAP 4.2
« blib/lib/Data/Stag/ChainHandler.pm ↑ Summary blib/lib/Data/Stag/HashDB.pm »
1 package Data::Stag::SxprWriter;
2  
3 =head1 NAME
4  
5 Data::Stag::SxprWriter - writes Stag S-expression format
6  
7 =head1 SYNOPSIS
8  
9  
10 =cut
11  
12 =head1 DESCRIPTION
13  
14 writes lisp style s-expressions
15  
16 note: more limited than normal s-expressions; all nodes are treated as
17 functions with one argument.
18  
19 all leaf/data elements treated as functions with one argument
20  
21 all other elements treated as functions with list arguments
22  
23 =head1 PUBLIC METHODS -
24  
25 =cut
26  
27 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 7 ▶use base qw(Data::Stag::Writer Data::Stag::Writer);
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 7 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 7 $VERSION="0.14";
32  
33 0 ▶sub fmtstr {
Subroutine fmtstr: not called CC=1 SCAR=6.9
Pod undocumented
34 0 return 'sxpr';
35 }
36  
37 495 ▶sub indent_txt {
Subroutine indent_txt: called CC=1 SCAR=0.0
Pod undocumented
38 495 my $self = shift;
39 495 my $stack = $self->stack;
40 495 return " " x scalar(@$stack);
41 }
42  
43 2484 ▶sub this_line {
Subroutine this_line: called CC=2 SCAR=6.9
Pod undocumented
44 2484 my $self = shift;
45 2484 ▶ $self->{_this_line} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 687 1797 2484
46 2484 return $self->{_this_line};
47 }
48  
49 687 ▶sub o {
Subroutine o: called CC=6 SCAR=17.9
Pod undocumented
50 687 my $self = shift;
51 687 my $o = "@_";
52 687 my $pre = " ";
53  
54 687 ▶ if (($self->this_line &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->this_line and length($self->this_line) + length($o) > 60 or $o =~ /^\(/) { } 253 434 687
Condition100%6/6
$self->this_line and length($self->this_line) + length($o) > 60 or $o =~ /^\(/
l!l&&r!l&&!r
3250434
$self->this_line and length($self->this_line) + length($o) > 60
!ll&&!rl&&r
116733
MC/DC66%2/3
$self->this_line and length($self->this_line) + length($o) > 60 or $o =~ /^\(/
$self->this_line length($self->this_line) + length($o) > 60 $o =~ /^\(/
Truth table80%4/5
A and B or C
A= $self->this_lineB= length($self->this_line) + length($o) > 60C= $o =~ /^\(/
ABCresult
11X1
0X11
1011
0X00
1000
55 length($self->this_line) + length($o) >
56 60) ||
57 # $o =~ /^[\(\)]/) {
58 $o =~ /^\(/) {
59 253 ▶ if ($self->indent_txt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->indent_txt) { } 242 11 253
60 242 $pre = "\n" . $self->indent_txt;
61 }
62 else {
63 11 $pre = "'";
64 }
65 253 $self->this_line($pre.$o);
66 }
67 else {
68 434 ▶ if ($o =~ /^\)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o =~ /^\)/) 253 181 434
69 253 $pre = "";
70 }
71 434 $self->this_line($self->this_line . $pre.$o);
72 }
73 687 $self->addtext( $pre.$o );
74  
75 }
76  
77 253 ▶sub start_event {
Subroutine start_event: called CC=3 SCAR=11.3
Pod documented
78 253 my $self = shift;
79 253 my $ev = shift;
80 253 ▶ if (!defined($ev)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ev) 2 251 253
81 2 $ev = '';
82 }
83 253 my $stack = $self->stack;
84 253 ▶ if ($self->use_color) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_color) { } 0 253 253
85 0 $self->o(color('white'));
86 0 $self->o('('.color('red').$ev);
87 }
88 else {
89 253 $self->o("($ev");
90 }
91 253 push(@$stack, $ev);
92 }
93 253 ▶sub end_event {
Subroutine end_event: called CC=5 SCAR=16.7
Pod documented
94 253 my $self = shift;
95 253 my $ev = shift;
96 253 my $stack = $self->stack;
97 253 my $popped = pop(@$stack);
98 253 ▶ if ($ev && $popped ne $ev) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ev and $popped ne $ev) 0 253 253
Condition66%2/3
$ev and $popped ne $ev
!ll&&!rl&&r
22510
MC/DC0%0/2
$ev and $popped ne $ev
$ev $popped ne $ev
Truth table66%2/3
A and B
A= $evB= $popped ne $ev
ABresult
0X0
100
111
99 0 warn("uh oh; $ev ne $popped");
100 }
101 253 ▶ if ($self->use_color) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_color) { } 0 253 253
102 # $self->o(color('white'));
103 0 $self->o(')');
104 }
105 else {
106 253 $self->o(')');
107 }
108 253 ▶ if (!@$stack) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$stack) 11 242 253
109 11 $self->o("\n");
110 }
111 253 return $ev;
112 }
113 170 ▶sub evbody {
Subroutine evbody: called CC=4 SCAR=20.1
Pod documented
114 170 my $self = shift;
115 170 my $body = shift;
116 170 my $str;
117 170 ▶ if ($self->use_color) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_color) { } 0 170 170
118 0 ▶ if (!defined($body)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $body) { } 0 0 0
elsif ($body eq '0') { } 0 0 0
119 0 $str = color('white').'""';
120 }
121 elsif ($body eq '0') {
122 0 $str = color('white').'"'.color('green').'0'.color('white').'"';
123 }
124 else {
125 0 $body =~ s/\(/\\\(/g;
126 0 $body =~ s/\)/\\\)/g;
127 0 $body =~ s/\"/\\\"/g;
128 0 $str = color('white').'"'.color('green').$body.color('white').'"';
129 }
130 }
131 else {
132 170 $str = lispesc($body);
133 }
134 170 $self->o($str);
135 170 return;
136 }
137  
138 170 ▶sub lispesc {
Subroutine lispesc: called CC=3 SCAR=11.0
Pod undocumented
139 170 my $w = shift;
140 170 ▶ return '""' unless defined $w;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $w 2 168 170
141 168 ▶ return '"0"' if $w eq '0';
Branch: 1 branch
BranchTrueFalseTotal
if $w eq 0 0 168 168
142 168 $w =~ s/\(/\\\(/g;
143 168 $w =~ s/\)/\\\)/g;
144 168 $w =~ s/\"/\\\"/g;
145 168 return '"'.$w.'"';
146 }
147  
148 0 ▶sub color {
Subroutine color: not called CC=1 SCAR=6.9
Pod undocumented
149 0 Term::ANSIColor::color(@_);
150 }
151  
152  
153 7 1;
« blib/lib/Data/Stag/ChainHandler.pm ↑ Summary blib/lib/Data/Stag/HashDB.pm »