blib/lib/JSON/SL/Tuba.pm

filter: Statementstmt 91.1% 62 / 68 Branchbran 66.6% 12 / 18 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 92.8% 13 / 14 Podpod 50.0% 2 / 4 totaltotal 79.8% 91 / 114 CC 12 SCAR 12.1
CC
12
Cov
83%
new
8.0
accum
3.1
BEGIN
3.0
CRAP 3.4
↑ Summary blib/lib/JSON/SL/EscapeTH.pm »
1 package JSON::SL::Tuba;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use JSON::SL;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 our @EXPORT;
7  
8 2 my (%ActionMap,%TypeMap);
9 2 my $_cg_typehash;
10 2 my $_cg_modehash;
11  
12 2 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=11.0
13 2 %ActionMap = (
14 '+' => 'start',
15 '-' => 'end',
16 '>' => 'on'
17 );
18 2 %TypeMap = (
19 '{' => 'object',
20 '[' => 'list',
21 'c' => 'data',
22 'D' => 'json',
23 '#' => 'key',
24 '"' => 'string',
25 '^' => 'special',
26 '?' => 'boolean',
27 '=' => 'number',
28 '~' => 'null'
29 );
30  
31 2 ▶ while (my ($sym,$name) = each %ActionMap) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %ActionMap) 6 2 8
32 6 $_cg_modehash->{uc($name)} = ord($sym);
33 }
34 2 ▶ while (my ($sym,$name) = each %TypeMap) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %TypeMap) 20 2 22
35 20 $_cg_typehash->{uc($name)} = ord($sym);
36 }
37 }
38  
39 2 ▶use Constant::Generate $_cg_typehash, prefix => "TUBA_TYPE_", export => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 2 ▶use Constant::Generate $_cg_modehash, prefix => "TUBA_MODE_", export =>1;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 2 our %CloseTokens = (
43 '{' => '}',
44 '"' => '"',
45 '[' => ']'
46 );
47  
48 2 ▶sub new {
Subroutine new: called CC=6 SCAR=20.8
Pod undocumented
49 2 my ($cls,%options) = @_;
50 2 my $o = $cls->_initialize();
51
52 2 ▶ unless (exists $options{accum_kv} and
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $options{"accum_kv"} and not delete $options{"accum_kv"}) 2 0 2
Condition33%1/3
exists $options{"accum_kv"} and not delete $options{"accum_kv"}
!ll&&!rl&&r
200
MC/DC0%0/2
exists $options{"accum_kv"} and not delete $options{"accum_kv"}
exists $options{"accum_kv"} not delete $options{"accum_kv"}
Truth table33%1/3
A and not(B)
A= exists $options{"accum_kv"}B= not delete $options{"accum_kv"}
ABresult
0X0
100
111
53 not delete $options{accum_kv}) {
54 2 $o->accum_kv(1);
55 }
56 2 ▶ unless (exists $options{accum_all}and
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $options{"accum_all"} and not delete $options{"accum_all"}) 2 0 2
Condition33%1/3
exists $options{"accum_all"} and not delete $options{"accum_all"}
!ll&&!rl&&r
200
MC/DC0%0/2
exists $options{"accum_all"} and not delete $options{"accum_all"}
exists $options{"accum_all"} not delete $options{"accum_all"}
Truth table33%1/3
A and not(B)
A= exists $options{"accum_all"}B= not delete $options{"accum_all"}
ABresult
0X0
100
111
57 not delete $options{accum_all}) {
58 2 $o->accum_all(1);
59 }
60 2 ▶ while (my ($k,$v) = each %options) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %options) 0 2 2
61 0 $o->can($k)->($o,$v);
62 }
63 2 return $o;
64 }
65  
66 # TODO: I can't think why I've hidden this?
67 {
68 2 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
69 2 *parse = *_parse;
70 }
71  
72 # set accumulator parameters:
73 3 ▶sub accum {
Subroutine accum: called CC=3 SCAR=11.3
Pod documented
74 3 my ($tuba,%modes) = @_;
75 3 ▶ while (my ($mode,$bool) = each %modes) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %modes) 15 3 18
76 15 ▶ if ($mode !~ m{[\=\~\?\#"]}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mode =~ /[\=\~\?\#"]/) 0 15 15
77 0 die("Invalid mode '$mode'. Mode must be one of [^#\"]");
78 }
79 15 $tuba->_ax_opt(ord("$mode"), $bool);
80 }
81 }
82  
83 5 ▶sub accum_enabled_for {
Subroutine accum_enabled_for: called CC=2 SCAR=7.6
Pod undocumented
84 5 my ($tuba,$mode) = @_;
85 5 ▶ if ($mode !~ m{[\=\~\?\#"]}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mode =~ /[\=\~\?\#"]/) 0 5 5
86 0 die("Invalid type '$mode'. Mode must be one of [^#\"]");
87 }
88 5 return $tuba->_ax_opt(ord("$mode"))
89 }
90  
91 3 ▶sub accum_all {
Subroutine accum_all: called CC=2 SCAR=7.2
Pod documented
92 3 my ($tuba,$boolean) = @_;
93 3 ▶ if (@_ != 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ != 2) 0 3 3
94 0 die("Must have boolean argument!");
95 }
96 my %opts = map {
97 3 $_, $boolean
98 } ('=','~','#','?','"');
99 3 $tuba->accum(%opts);
100 }
101  
102 #build convenience methods:
103 2 foreach (['key', '#'],
104 ['string', '"'],
105 ['number', '='],
106 ['boolean', '?'],
107 ['null', '~']
108 ) {
109  
110 10 my ($mode,$sym) = @$_;
111 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
112 10 ▶ *{"accum_$mode"} = sub {
Subroutine __ANON__: not called CC=1 SCAR=2.6
113 0 my ($tuba,$bool) = @_;
114 0 $tuba->_ax_opt(ord($sym), $bool);
115 }
116 10 }
117  
118 2 1;
119  
120 __END__
↑ Summary blib/lib/JSON/SL/EscapeTH.pm »