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   75120 use base qw(Exporter);
  7         56  
  7         1079  
4 7     7   57 use strict;
  7         15  
  7         142  
5 7     7   46 use warnings;
  7         16  
  7         318  
6              
7 7     7   3399 use PYX::Utils qw(decode);
  7         93822  
  7         158  
8 7     7   592 use Readonly;
  7         19  
  7         2571  
9              
10             # Constants.
11             Readonly::Array our @EXPORT_OK => qw(attribute char comment end_element instruction
12             start_element);
13              
14             our $VERSION = 0.09;
15              
16             # Encode attribute as PYX.
17             sub attribute {
18 2     2 1 5 my (@attr) = @_;
19              
20 2         3 my @ret = ();
21 2         6 while (@attr) {
22 2         5 my ($key, $val) = (shift @attr, shift @attr);
23 2         12 push @ret, "A$key ".decode($val);
24             }
25              
26 2         26 return @ret;
27             }
28              
29             # Encode characters between elements as PYX.
30             sub char {
31 2     2 1 869 my $char = shift;
32              
33 2         8 return '-'.decode($char);
34             }
35              
36             # Encode comment as PYX.
37             sub comment {
38 2     2 1 884 my $comment = shift;
39              
40 2         8 return '_'.decode($comment);
41             }
42              
43             # Encode end of element as PYX.
44             sub end_element {
45 1     1 1 87 my $elem = shift;
46              
47 1         5 return ')'.$elem;
48             }
49              
50             # Encode instruction as PYX.
51             sub instruction {
52 3     3 1 1356 my ($target, $code) = @_;
53              
54 3         10 my $ret = '?'.decode($target);
55 3 100       41 if ($code) {
56 1         9 $ret .= ' '.decode($code);
57             }
58              
59 3         13 return $ret;
60             }
61              
62             # Encode begin of element as PYX.
63             sub start_element {
64 3     3 1 2089 my ($elem, @attr) = @_;
65              
66 3         6 my @ret = ();
67 3         8 push @ret, '('.$elem;
68 3 100       10 if (@attr) {
69 2         6 push @ret, attribute(@attr);
70             }
71              
72 3         9 return @ret;
73             }
74              
75             1;
76              
77             __END__