Decode.pm

filter: Statementstmt 71.7% 33 / 46 Branchbran 50.0% 17 / 34 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 72.7% 8 / 11 Podpod 100% 5 / 5 totaltotal 65.6% 63 / 96 CC 18 SCAR 26.1
CC
18
Cov
62%
new
22.9
_log_cb
20.0
_warn_cb
4.0
CRAP 13.6
« Decode/Tokenizer.pm ↑ Summary Decode/Array.pm »
1 #
2 # parse and transform PHP source files
3 #
4 package PHP::Decode;
5  
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use PHP::Decode::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use PHP::Decode::Transformer;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $VERSION = '0.303';
12  
13 746 ▶sub new {
Subroutine new: called CC=12 SCAR=31.3
Pod documented
14 746 my ($class, %args) = @_;
15  
16 my $parser = PHP::Decode::Parser->new(strmap => {},
17 exists $args{inscript} ? (inscript => $args{inscript}) : (),
18 exists $args{filename} ? (filename => $args{filename}) : (),
19 exists $args{max_strlen} ? (max_strlen => $args{max_strlen}) : (),
20 exists $args{log} ? (log => $args{log}) : (),
21 exists $args{debug} ? (debug => $args{debug}) : (),
22 746 ▶ exists $args{warn} ? (warn => $args{warn}) : ());
Branch: 6 branches
BranchTrueFalseTotal
exists $args{'inscript'} ? : 746 0 746
exists $args{'filename'} ? : 0 746 746
exists $args{'max_strlen'} ? : 0 746 746
exists $args{'log'} ? : 0 746 746
exists $args{'debug'} ? : 0 746 746
exists $args{'warn'} ? : 746 0 746
23  
24 my $ctx = PHP::Decode::Transformer->new(parser => $parser,
25 exists $args{skip} ? (skip => $args{skip}) : (),
26 exists $args{with} ? (with => $args{with}) : (),
27 exists $args{max_loop} ? (max_loop => $args{max_loop}) : (),
28 exists $args{log} ? (log => \&_log_cb) : (),
29 746 ▶ exists $args{warn} ? (warn => \&_warn_cb) : ());
Branch: 5 branches
BranchTrueFalseTotal
exists $args{'skip'} ? : 746 0 746
exists $args{'with'} ? : 746 0 746
exists $args{'max_loop'} ? : 0 746 746
exists $args{'log'} ? : 0 746 746
exists $args{'warn'} ? : 746 0 746
30  
31 746 return bless {
32 ctx => $ctx,
33 }, $class;
34 }
35  
36 0 ▶sub _log_cb {
Subroutine _log_cb: not called CC=4 SCAR=30.0
37 0 my ($ctx, $action, $stmt, $fmt) = (shift, shift, shift, shift);
38  
39 0 my $parser = $ctx->{parser};
40 0 ▶ my $flg = $ctx->{skipundef} ? '! ' : '';
Branch: 1 branch
BranchTrueFalseTotal
$ctx->{'skipundef'} ? : 0 0 0
41 0 ▶ if ($ctx->{incall}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ctx->{'incall'}) { } 0 0 0
elsif ($ctx->{'infunction'}) { } 0 0 0
42 0 $parser->{log}->($flg . "[$ctx->{infunction}] $action $stmt", $fmt, @_);
43 } elsif ($ctx->{infunction}) {
44 0 $parser->{log}->("<$ctx->{infunction}> $action $stmt", $fmt, @_);
45 } else {
46 0 $parser->{log}->($flg . "$action $stmt", $fmt, @_);
47 }
48 }
49  
50 1933 ▶sub _warn_cb {
Subroutine _warn_cb: called CC=4 SCAR=13.9
51 1933 my ($ctx, $action, $stmt, $fmt) = (shift, shift, shift, shift);
52  
53 1933 my $parser = $ctx->{parser};
54 1933 ▶ my $flg = $ctx->{skipundef} ? '! ' : '';
Branch: 1 branch
BranchTrueFalseTotal
$ctx->{'skipundef'} ? : 609 1324 1933
55 1933 ▶ if ($ctx->{incall}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ctx->{'incall'}) { } 95 1838 1933
elsif ($ctx->{'infunction'}) { } 416 1422 1838
56 95 $parser->{warn}->($flg . "[$ctx->{infunction}] $action $stmt", $fmt, @_);
57 } elsif ($ctx->{infunction}) {
58 416 $parser->{warn}->("<$ctx->{infunction}> $action $stmt", $fmt, @_);
59 } else {
60 1422 $parser->{warn}->($flg . "$action $stmt", $fmt, @_);
61 }
62 }
63  
64 0 ▶sub parse {
Subroutine parse: not called CC=1 SCAR=6.9
Pod documented
65 0 my ($self, $line) = @_;
66 0 my $parser = $self->{ctx}{parser};
67 0 my $str = $parser->setstr($line);
68  
69 0 return $self->{ctx}->parse_eval($str);
70 }
71  
72 0 ▶sub exec {
Subroutine exec: not called CC=1 SCAR=6.9
Pod documented
73 0 my ($self, $stmt) = @_;
74  
75 0 return $self->{ctx}->exec_eval($stmt);
76 }
77  
78 746 ▶sub eval {
Subroutine eval: called CC=1 SCAR=0.0
Pod documented
79 746 my ($self, $line) = @_;
80 746 my $parser = $self->{ctx}{parser};
81 746 my $str = $parser->setstr($line);
82  
83 746 my $stmt = $self->{ctx}->parse_eval($str);
84 746 return $self->{ctx}->exec_eval($stmt);
85 }
86  
87 746 ▶sub format {
Subroutine format: called CC=1 SCAR=0.0
Pod documented
88 746 my ($self, $stmt, $fmt) = @_;
89 746 my $parser = $self->{ctx}{parser};
90  
91 746 return $parser->format_stmt($stmt, $fmt);
92 }
93  
94 2 1;
95  
96 __END__
« Decode/Tokenizer.pm ↑ Summary Decode/Array.pm »