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