blib/lib/PYX/Stack.pm

filter: Statementstmt 100% 63 / 63 Branchbran 100% 10 / 10 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 12 / 12 Podpod 100% 4 / 4 totaltotal 100% 94 / 94 SCAR 19.5
CC
7
Cov
100%
_end_element
5.0
_final
2.0
_start_element
2.0
CRAP 7.0
↑ Summary
1 package PYX::Stack;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 ▶use Class::Utils qw(set_params);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use PYX::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 our $VERSION = 0.05;
11  
12 # Constructor.
13 sub new {
14 15 ▶ my ($class, @params) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
15 15 my $self = bless {}, $class;
16  
17 # Check bad end of element.
18 15 $self->{'bad_end'} = 0;
19  
20 # Output handler.
21 15 $self->{'output_handler'} = \*STDOUT;
22  
23 # Verbose.
24 15 $self->{'verbose'} = 0;
25  
26 # Process params.
27 15 set_params($self, @params);
28  
29 # PYX::Parser object.
30 $self->{'_pyx_parser'} = PYX::Parser->new(
31 'callbacks' => {
32 'end_element' => \&_end_element,
33 'start_element' => \&_start_element,
34 'final' => \&_final,
35 },
36 'non_parser_options' => {
37 'bad_end' => $self->{'bad_end'},
38 'stack' => [],
39 'verbose' => $self->{'verbose'},
40 },
41 13 'output_handler' => $self->{'output_handler'},
42 );
43  
44 # Object.
45 13 return $self;
46 }
47  
48 # Parse pyx text or array of pyx text.
49 sub parse {
50 4 ▶ my ($self, $pyx, $out) = @_;
Subroutine parse: called CC=1 SCAR=0.0
Pod documented
51 4 $self->{'_pyx_parser'}->parse($pyx, $out);
52 1 return;
53 }
54  
55 # Parse file with pyx text.
56 sub parse_file {
57 4 ▶ my ($self, $file, $out) = @_;
Subroutine parse_file: called CC=1 SCAR=0.0
Pod documented
58 4 $self->{'_pyx_parser'}->parse_file($file, $out);
59 1 return;
60 }
61  
62 # Parse from handler.
63 sub parse_handler {
64 4 ▶ my ($self, $input_file_handler, $out) = @_;
Subroutine parse_handler: called CC=1 SCAR=0.0
Pod documented
65 4 $self->{'_pyx_parser'}->parse_handler($input_file_handler, $out);
66 1 return;
67 }
68  
69 # End of element.
70 sub _end_element {
71 15 ▶ my ($pyx_parser_obj, $elem) = @_;
Subroutine _end_element: called CC=5 SCAR=16.1
72 15 my $stack_ar = $pyx_parser_obj->{'non_parser_options'}->{'stack'};
73 15 ▶ if ($stack_ar->[-1] eq $elem) {
Branch: 2 branches
BranchTrueFalseTotal
if ($stack_ar->[-1] eq $elem) { } 9 6 15
elsif ($pyx_parser_obj->{'non_parser_options'}{'bad_end'}) { } 3 3 6
74 9 pop @{$stack_ar};
75 } elsif ($pyx_parser_obj->{'non_parser_options'}->{'bad_end'}) {
76 3 err 'Bad end of element.',
77 'Element', $elem;
78 }
79 12 ▶ if ($pyx_parser_obj->{'non_parser_options'}->{'verbose'}
Branch: 1 branch
BranchTrueFalseTotal
if ($pyx_parser_obj->{"non_parser_options"}{"verbose"} and @{$stack_ar;} > 0) 6 6 12
Condition100%3/3
$pyx_parser_obj->{"non_parser_options"}{"verbose"} and @{$stack_ar;} > 0
!ll&&!rl&&r
336
MC/DC100%2/2
$pyx_parser_obj->{"non_parser_options"}{"verbose"} and @{$stack_ar;} > 0
$pyx_parser_obj->{"non_parser_options"}{"verbose"} @{$stack_ar;} > 0
Truth table100%3/3
A and B
A= $pyx_parser_obj->{"non_parser_options"}{"verbose"}B= @{$stack_ar;} > 0
ABresult
0X0
100
111
80 9 && @{$stack_ar} > 0) {
81  
82 6 my $out = $pyx_parser_obj->{'output_handler'};
83 6 print {$out} join('/', @{$stack_ar}), "\n";
84 }
85 12 return;
86 }
87  
88 # Finalize.
89 sub _final {
90 9 ▶ my $pyx_parser_obj = shift;
Subroutine _final: called CC=2 SCAR=6.9
91 9 my $stack_ar = $pyx_parser_obj->{'non_parser_options'}->{'stack'};
92 9 ▶ if (@{$stack_ar} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$stack_ar;} > 0) 6 3 9
93 6 err 'Stack has some elements.';
94 }
95 3 return;
96 }
97  
98 # Start of element.
99 sub _start_element {
100 24 ▶ my ($pyx_parser_obj, $elem) = @_;
Subroutine _start_element: called CC=2 SCAR=6.9
101 24 my $stack_ar = $pyx_parser_obj->{'non_parser_options'}->{'stack'};
102 24 my $out = $pyx_parser_obj->{'output_handler'};
103 24 push @{$stack_ar}, $elem;
104 24 ▶ if ($pyx_parser_obj->{'non_parser_options'}->{'verbose'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pyx_parser_obj->{"non_parser_options"}{"verbose"}) 9 15 24
105 9 print {$out} join('/', @{$stack_ar}), "\n";
106 }
107 24 return;
108 }
109  
110 6 1;
111  
112 __END__
↑ Summary