File Coverage

blib/lib/PYX.pm
Criterion Covered Total %
statement 38 38 100.0
branch 4 4 100.0
condition n/a
subroutine 11 11 100.0
pod 6 6 100.0
total 59 59 100.0


line stmt bran cond sub pod time code
1             package PYX;
2              
3 7     7   148510 use base qw(Exporter);
  7         15  
  7         1143  
4 7     7   44 use strict;
  7         17  
  7         265  
5 7     7   34 use warnings;
  7         24  
  7         462  
6              
7 7     7   4842 use PYX::Utils qw(decode);
  7         103304  
  7         166  
8 7     7   630 use Readonly;
  7         14  
  7         3202  
9              
10             # Constants.
11             Readonly::Array our @EXPORT_OK => qw(attribute char comment end_element instruction
12             start_element);
13              
14             our $VERSION = 0.10;
15              
16             # Encode attribute as PYX.
17             sub attribute {
18 2     2 1 5 my (@attr) = @_;
19              
20 2         5 my @ret = ();
21 2         6 while (@attr) {
22 2         7 my ($key, $val) = (shift @attr, shift @attr);
23 2         10 push @ret, "A$key ".decode($val);
24             }
25              
26 2         27 return @ret;
27             }
28              
29             # Encode characters between elements as PYX.
30             sub char {
31 2     2 1 358363 my $char = shift;
32              
33 2         11 return '-'.decode($char);
34             }
35              
36             # Encode comment as PYX.
37             sub comment {
38 2     2 1 339557 my $comment = shift;
39              
40 2         12 return '_'.decode($comment);
41             }
42              
43             # Encode end of element as PYX.
44             sub end_element {
45 1     1 1 276380 my $elem = shift;
46              
47 1         5 return ')'.$elem;
48             }
49              
50             # Encode instruction as PYX.
51             sub instruction {
52 3     3 1 353375 my ($target, $code) = @_;
53              
54 3         16 my $ret = '?'.decode($target);
55 3 100       33 if ($code) {
56 1         3 $ret .= ' '.decode($code);
57             }
58              
59 3         16 return $ret;
60             }
61              
62             # Encode begin of element as PYX.
63             sub start_element {
64 3     3 1 296614 my ($elem, @attr) = @_;
65              
66 3         7 my @ret = ();
67 3         8 push @ret, '('.$elem;
68 3 100       15 if (@attr) {
69 2         9 push @ret, attribute(@attr);
70             }
71              
72 3         13 return @ret;
73             }
74              
75             1;
76              
77             __END__