File Coverage

blib/lib/SMIL/XMLBase.pm
Criterion Covered Total %
statement 48 70 68.5
branch 11 20 55.0
condition 10 18 55.5
subroutine 12 19 63.1
pod 0 17 0.0
total 81 144 56.2


line stmt bran cond sub pod time code
1             package SMIL::XMLBase;
2              
3             $VERSION = "0.898";
4              
5             $ZERO_STRING = "ZERO_STRING";
6             $TRUE = 'true';
7              
8 1     1   873 use SMIL::MediaAttributes;
  1         3  
  1         2342  
9              
10             my $debug = 1;
11              
12             my @tabBuffer = ();
13              
14             my $tab_count = 4;
15             my $TAB = " " x $tab_count;
16             my $check_errors = 1;
17              
18             sub enableErrorChecking {
19 0     0 0 0 $check_errors = 1;
20             }
21              
22             sub disableErrorChecking {
23 0     0 0 0 $check_errors = 0;
24             }
25              
26             sub increaseTabBuffer {
27 9     9 0 11 my $self = shift;
28 9         22 push @tabBuffer, $TAB;
29             }
30              
31             sub decreaseTabBuffer {
32 9     9 0 18 pop @tabBuffer;
33             }
34              
35             sub getTabBuffer {
36 20     20 0 61 return( join "", @tabBuffer );
37             }
38              
39             sub new {
40 20     20 0 65 my $type = shift;
41 20         28 my $self = {};
42 20         40 bless $self, $type;
43              
44 20         92 $self->init( @_ );
45 20         66 return $self;
46             }
47              
48             sub setPrivate {
49              
50 0     0 0 0 my $self = shift;
51 0         0 my $key = shift;
52 0         0 my $value = shift;
53              
54 0 0 0     0 if( $key and $value ) {
55 0 0       0 $self->{_private} = {} if !$self->{_private};
56 0         0 $self->{_private}->{ $key } = $value;
57             }
58             }
59              
60             sub getPrivate {
61 0     0 0 0 my $self = shift;
62 0         0 my $key = shift;
63            
64 0         0 return( $self->{_private}->{ $key } ); # if $self->{_private};
65             }
66              
67             sub setTag {
68 20     20 0 27 my $self = shift;
69 20         26 my $tag = shift;
70 20         150 $self->{_tag} = $tag;
71             }
72              
73             sub setFavorite {
74 4     4 0 8 my $self = shift;
75 4         6 my $favorite = shift;
76 4         16 $self->{_favorite} = $favorite;
77             }
78              
79             sub getTag {
80 18     18 0 21 my $self = shift;
81 18         98 return $self->{_tag};
82             }
83              
84             sub setAttributes {
85 17     17 0 27 my $self = shift;
86 17         72 $self->{_attributes} = { @_ };
87             }
88              
89             sub setAttribute {
90 0     0 0 0 my $self = shift;
91 0         0 my $attrib = shift;
92 0         0 my $value = shift;
93 0         0 my $attribs = $self->{_attributes};
94 0         0 $$attribs{ $attrib } = $value;
95             }
96              
97             sub getAttributes {
98 0     0 0 0 my $self = shift;
99 0         0 return $self->{_attributes};
100             }
101              
102             sub getAttribute {
103 0     0 0 0 my $self = shift;
104 0         0 my $attrib = shift;
105 0         0 return $self->{_attributes}->{$attrib};
106             }
107              
108             sub createValidAttributes {
109 14     14 0 22 my $self = shift;
110 14         17 my $arg_hash_ref = shift;
111 14         128 my $valid_arr_ref = shift;
112 14         24 my %return_hash = ();
113              
114 14         29 foreach $item ( @$valid_arr_ref ) {
115 117 100 100     685 $return_hash{ $item } = $$arg_hash_ref{ $item }
116             if( $$arg_hash_ref{ $item } ||
117             # Allow namespaces...
118             $item =~ /:/ );
119             }
120              
121             # Respect namespaces
122 14         49 foreach $item ( keys %$arg_hash_ref ) {
123 45 50       110 $return_hash{ $item } = $$arg_hash_ref{ $item }
124             if $item =~ /:/;
125             }
126              
127 14         31 foreach $time_attribute ( @timeAtts ) {
128             # Special cases are handled here:
129 84 0 33     295 if( $return_hash{ $time_attribute } &&
      33        
130             $return_hash{ $time_attribute } !~ /s$/ &&
131             $return_hash{ $time_attribute } !~ /:\d+\.\d+$/ ) {
132 0         0 $return_hash{ $time_attribute } .= "s";
133             }
134             }
135              
136 14         85 return %return_hash;
137             }
138              
139             sub _build_attributes {
140 20     20   26 my $return_string = "";
141 20         21 my $self = shift;
142 20         28 my $hash_ref = $self->{_attributes};
143              
144 20         33 my $favorite = $self->{_favorite};
145              
146 20 100       37 if( $favorite ) {
147 4 50       19 $return_string .= " " . $favorite . "=\"" . $$hash_ref{ $favorite } . "\""
148             if $$hash_ref{ $favorite };
149             }
150              
151 20         84 foreach $key ( keys %$hash_ref ) {
152 39 100 100     97 if( !$favorite or $key ne $favorite ) {
153 35         49 my $value = $$hash_ref{ $key };
154 35 50 66     128 $value = "0" if $value && $value =~ /ZERO_STRING/;
155 35 100       121 $return_string .= " " . $key . "=\"" . $value . "\""
156             if $$hash_ref{ $key };
157             }
158             }
159 20         86 return $return_string;
160             }
161              
162             sub init {
163 20     20 0 31 my $self = shift;
164 20         26 my $tag = shift;
165             # print "Setting tag to: $tag : " . ref( $self ) . "\n" if $debug;
166 20         102 $self->setTag( $tag );
167             }
168              
169             1;
170