blib/lib/Net/SPOCP/SExpr.pm

filter: Statementstmt 75.0% 45 / 60 Branchbran 50.0% 7 / 14 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 6 totaltotal 63.7% 65 / 102 CC 13 SCAR 16.6
CC
13
Cov
68%
create
11.7
parse
6.0
new
5.6
CRAP 5.2
« blib/lib/Net/SPOCP/Protocol.pm ↑ Summary SPOCP/SExpr/Parser.y »
1 package Net::SPOCP::SExpr;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 @Net::SPOCP::SExpr::ISA = qw(Net::SPOCP);
8  
9 # [ [ 'resource' , 'etc' 'group' ] [ 'subject' 'uid' 'leifj' ] [ 'foo' '*' '1' '2' ] ]
10  
11 package Net::SPOCP::SExpr::Atom;
12 1 @Net::SPOCP::SExpr::Atom::ISA = qw(Net::SPOCP::SExpr);
13  
14 sub new
15 42 ▶ {
Subroutine new: called CC=2 SCAR=7.6
16 42 my $self = shift;
17 42 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
0420
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
18  
19 42 bless { data => $_[0], length => length($_[0]) },$class;
20 }
21  
22 sub toString
23 62 ▶ {
Subroutine toString: called CC=1 SCAR=0.0
24 62 sprintf("%d:%s",$_[0]->{length},$_[0]->{data});
25 }
26  
27 package Net::SPOCP::SExpr;
28  
29 sub create
30 64 ▶ {
Subroutine create: called CC=6 SCAR=24.6
Pod undocumented
31 64 my ($class,$x) = @_;
32  
33 64 ▶ if (ref $x eq 'ARRAY')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $x eq 'ARRAY') { } 22 42 64
elsif (ref $x eq 'HASH') { } 0 42 42
34 {
35 22 my @out;
36 22 foreach my $item (@{$x})
37 {
38 61 push(@out,$class->create($item));
39 }
40 22 return bless \@out,$class;
41 }
42 elsif (ref $x eq 'HASH')
43 {
44 0 my @out;
45 0 foreach my $key (keys %{$x})
46 {
47 0 my $v = $class->create($x->{$key});
48 0 ▶ if (ref $x->{$key})
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x->{$key}) { } 0 0 0
49 {
50 0 unshift(@{$v},$class->create($key));
51 0 push(@out,$v);
52 }
53 else
54 {
55 0 push(@out,bless [$class->create($key),$v],$class);
56 }
57 }
58 0 return bless \@out,$class;
59 }
60 else
61 {
62 42 return Net::SPOCP::SExpr::Atom->new($x);
63 }
64 }
65  
66 sub new
67 2 ▶ {
Subroutine new: called CC=5 SCAR=17.3
Pod undocumented
68 2 my $self = shift;
69 2 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
70 2 my @expr = @_;
71 2 ▶ $expr[0] = "" unless defined $expr[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr[0] 0 2 2
72  
73 2 ▶ if (ref $expr[0] eq 'ARRAY')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $expr[0] eq 'ARRAY') { } 0 2 2
elsif ($expr[0] =~ /^\(.*\)$/) { } 1 1 2
74 {
75 0 return $class->create($expr[0]);
76 }
77 elsif ($expr[0] =~ m/^\(.*\)$/)
78 {
79 1 return $class->create($class->toList($expr[0]));
80 }
81 else
82 {
83 1 return $class->create(\@expr);
84 }
85 }
86  
87 sub parse
88 0 ▶ {
Subroutine parse: not called CC=2 SCAR=17.9
Pod undocumented
89 0 my $self = shift;
90 0 my $io = shift;
91  
92 0 my @stack;
93  
94 0 ▶ while ($_)
Branch: 1 branch
BranchTrueFalseTotal
if ($_) 0 0 0
95 {
96
97 }
98 }
99  
100 sub items
101 34 ▶ {
Subroutine items: called CC=1 SCAR=0.0
Pod undocumented
102 34 @{$_[0]};
103 }
104  
105 sub toString
106 34 ▶ {
Subroutine toString: called CC=2 SCAR=6.9
Pod undocumented
107 34 my $out = "(";
108 34 foreach my $item ($_[0]->items)
109 {
110 91 $out .= $item->toString();
111 }
112 34 $out .= ")";
113  
114 34 $out;
115 }
116  
117 sub toList
118 1 ▶ {
Subroutine toList: called CC=1 SCAR=0.0
Pod undocumented
119 1 ▶ use Net::SPOCP::SExpr::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
120 1 my $self = shift;
121 1 my $sexpr = shift;
122  
123 1 my $parser = new Net::SPOCP::SExpr::Parser();
124 1 $parser->YYData->{INPUT} = $sexpr;
125 1 $parser->YYParse(yylex => \&Net::SPOCP::SExpr::Parser::yylex);
126 }
127  
128 1 1;
« blib/lib/Net/SPOCP/Protocol.pm ↑ Summary SPOCP/SExpr/Parser.y »