PYX.pm

filter: Statementstmt 100% 41 / 41 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 100% 6 / 6 totaltotal 100% 64 / 64 SCAR 13.9
CC
4
Cov
100%
attribute
2.0
instruction
2.0
start_element
2.0
CRAP 4.0
« PYX/Parser.pm ↑ Summary PYX/Format.pm »
1 package PYX;
2  
3 7 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 ▶use PYX::Utils qw(decode);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # Constants.
11 7 Readonly::Array our @EXPORT_OK => qw(attribute char comment end_element instruction
12 start_element);
13  
14 7 our $VERSION = 0.08;
15  
16 # Encode attribute as PYX.
17 sub attribute {
18 2 ▶ my (@attr) = @_;
Subroutine attribute: called CC=2 SCAR=6.9
Pod documented
19  
20 2 my @ret = ();
21 2 ▶ while (@attr) {
Branch: 1 branch
BranchTrueFalseTotal
if (@attr) 2 2 4
22 2 my ($key, $val) = (shift @attr, shift @attr);
23 2 push @ret, "A$key ".decode($val);
24 }
25  
26 2 return @ret;
27 }
28  
29 # Encode characters between elements as PYX.
30 sub char {
31 2 ▶ my $char = shift;
Subroutine char: called CC=1 SCAR=0.0
Pod documented
32  
33 2 return '-'.decode($char);
34 }
35  
36 # Encode comment as PYX.
37 sub comment {
38 2 ▶ my $comment = shift;
Subroutine comment: called CC=1 SCAR=0.0
Pod documented
39  
40 2 return '_'.decode($comment);
41 }
42  
43 # Encode end of element as PYX.
44 sub end_element {
45 1 ▶ my $elem = shift;
Subroutine end_element: called CC=1 SCAR=0.0
Pod documented
46  
47 1 return ')'.$elem;
48 }
49  
50 # Encode instruction as PYX.
51 sub instruction {
52 3 ▶ my ($target, $code) = @_;
Subroutine instruction: called CC=2 SCAR=6.9
Pod documented
53  
54 3 my $ret = '?'.decode($target);
55 3 ▶ if ($code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code) 1 2 3
56 1 $ret .= ' '.decode($code);
57 }
58  
59 3 return $ret;
60 }
61  
62 # Encode begin of element as PYX.
63 sub start_element {
64 3 ▶ my ($elem, @attr) = @_;
Subroutine start_element: called CC=2 SCAR=6.9
Pod documented
65  
66 3 my @ret = ();
67 3 push @ret, '('.$elem;
68 3 ▶ if (@attr) {
Branch: 1 branch
BranchTrueFalseTotal
if (@attr) 2 1 3
69 2 push @ret, attribute(@attr);
70 }
71  
72 3 return @ret;
73 }
74  
75 7 1;
76  
77 __END__
« PYX/Parser.pm ↑ Summary PYX/Format.pm »