line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::SPOCP::SExpr; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
17
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
657
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
@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
|
|
|
|
|
|
|
@Net::SPOCP::SExpr::Atom::ISA = qw(Net::SPOCP::SExpr); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new |
15
|
|
|
|
|
|
|
{ |
16
|
47
|
|
|
47
|
|
54
|
my $self = shift; |
17
|
47
|
|
33
|
|
|
151
|
my $class = ref $self || $self; |
18
|
|
|
|
|
|
|
|
19
|
47
|
|
|
|
|
273
|
bless { data => $_[0], length => length($_[0]) },$class; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub toString |
23
|
|
|
|
|
|
|
{ |
24
|
67
|
|
|
67
|
|
248
|
sprintf("%d:%s",$_[0]->{length},$_[0]->{data}); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
package Net::SPOCP::SExpr; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub create |
30
|
|
|
|
|
|
|
{ |
31
|
72
|
|
|
72
|
0
|
182
|
my ($class,$x) = @_; |
32
|
|
|
|
|
|
|
|
33
|
72
|
100
|
|
|
|
164
|
if (ref $x eq 'ARRAY') |
|
|
50
|
|
|
|
|
|
34
|
|
|
|
|
|
|
{ |
35
|
25
|
|
|
|
|
31
|
my @out; |
36
|
25
|
|
|
|
|
30
|
foreach my $item (@{$x}) |
|
25
|
|
|
|
|
45
|
|
37
|
|
|
|
|
|
|
{ |
38
|
68
|
|
|
|
|
163
|
push(@out,$class->create($item)); |
39
|
|
|
|
|
|
|
} |
40
|
25
|
|
|
|
|
97
|
return bless \@out,$class; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
elsif (ref $x eq 'HASH') |
43
|
|
|
|
|
|
|
{ |
44
|
0
|
|
|
|
|
0
|
my @out; |
45
|
0
|
|
|
|
|
0
|
foreach my $key (keys %{$x}) |
|
0
|
|
|
|
|
0
|
|
46
|
|
|
|
|
|
|
{ |
47
|
0
|
|
|
|
|
0
|
my $v = $class->create($x->{$key}); |
48
|
0
|
0
|
|
|
|
0
|
if (ref $x->{$key}) |
49
|
|
|
|
|
|
|
{ |
50
|
0
|
|
|
|
|
0
|
unshift(@{$v},$class->create($key)); |
|
0
|
|
|
|
|
0
|
|
51
|
0
|
|
|
|
|
0
|
push(@out,$v); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else |
54
|
|
|
|
|
|
|
{ |
55
|
0
|
|
|
|
|
0
|
push(@out,bless [$class->create($key),$v],$class); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
0
|
return bless \@out,$class; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
else |
61
|
|
|
|
|
|
|
{ |
62
|
47
|
|
|
|
|
106
|
return Net::SPOCP::SExpr::Atom->new($x); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub new |
67
|
|
|
|
|
|
|
{ |
68
|
3
|
|
|
3
|
0
|
159
|
my $self = shift; |
69
|
3
|
|
33
|
|
|
24
|
my $class = ref $self || $self; |
70
|
3
|
|
|
|
|
9
|
my @expr = @_; |
71
|
3
|
50
|
|
|
|
11
|
$expr[0] = "" unless defined $expr[0]; |
72
|
|
|
|
|
|
|
|
73
|
3
|
100
|
|
|
|
20
|
if (ref $expr[0] eq 'ARRAY') |
|
|
100
|
|
|
|
|
|
74
|
|
|
|
|
|
|
{ |
75
|
1
|
|
|
|
|
6
|
return $class->create($expr[0]); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
elsif ($expr[0] =~ m/^\(.*\)$/) |
78
|
|
|
|
|
|
|
{ |
79
|
1
|
|
|
|
|
7
|
return $class->create($class->toList($expr[0])); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
else |
82
|
|
|
|
|
|
|
{ |
83
|
1
|
|
|
|
|
8
|
return $class->create(\@expr); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub parse |
88
|
|
|
|
|
|
|
{ |
89
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
90
|
0
|
|
|
|
|
0
|
my $io = shift; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
0
|
my @stack; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
0
|
while ($_) |
95
|
|
|
|
|
|
|
{ |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub items |
101
|
|
|
|
|
|
|
{ |
102
|
37
|
|
|
37
|
0
|
39
|
@{$_[0]}; |
|
37
|
|
|
|
|
94
|
|
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub toString |
106
|
|
|
|
|
|
|
{ |
107
|
37
|
|
|
37
|
0
|
215
|
my $out = "("; |
108
|
37
|
|
|
|
|
75
|
foreach my $item ($_[0]->items) |
109
|
|
|
|
|
|
|
{ |
110
|
98
|
|
|
|
|
166
|
$out .= $item->toString(); |
111
|
|
|
|
|
|
|
} |
112
|
37
|
|
|
|
|
55
|
$out .= ")"; |
113
|
|
|
|
|
|
|
|
114
|
37
|
|
|
|
|
108
|
$out; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub toList |
118
|
|
|
|
|
|
|
{ |
119
|
1
|
|
|
1
|
|
520
|
use Net::SPOCP::SExpr::Parser; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
74
|
|
120
|
1
|
|
|
1
|
0
|
4
|
my $self = shift; |
121
|
1
|
|
|
|
|
3
|
my $sexpr = shift; |
122
|
|
|
|
|
|
|
|
123
|
1
|
|
|
|
|
9
|
my $parser = new Net::SPOCP::SExpr::Parser(); |
124
|
1
|
|
|
|
|
11
|
$parser->YYData->{INPUT} = $sexpr; |
125
|
1
|
|
|
|
|
22
|
$parser->YYParse(yylex => \&Net::SPOCP::SExpr::Parser::yylex); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |