File Coverage

blib/lib/SMIL/Body.pm
Criterion Covered Total %
statement 76 101 75.2
branch 10 26 38.4
condition 8 33 24.2
subroutine 14 17 82.3
pod 0 10 0.0
total 108 187 57.7


line stmt bran cond sub pod time code
1             package SMIL::Body;
2              
3             $VERSION = "0.898";
4              
5 1     1   6 use SMIL::XMLContainer;
  1         5  
  1         68  
6 1     1   696 use SMIL::Par;
  1         4  
  1         31  
7 1     1   766 use SMIL::Seq;
  1         4  
  1         26  
8 1     1   853 use SMIL::MediaFactory;
  1         32  
  1         120  
9 1     1   979 use SMIL::Switch;
  1         3  
  1         34  
10 1     1   1016 use SMIL::Code;
  1         3  
  1         106  
11              
12             @ISA = qw( SMIL::XMLContainer );
13              
14             $SEQ = "seq";
15             $PAR = "par";
16              
17 1     1   6 use Carp;
  1         3  
  1         3217  
18              
19             my $timelineStack = "timelineStack";
20             my $mediaStack = "mediaStack";
21             my $counter = "counter";
22             my $timeline = "timeline";
23             my $href = 'href';
24             my $anchors = 'anchors';
25             my $switch = 'switch';
26             my $medias = 'medias';
27             my $par_bug = 1;
28              
29             sub init {
30 1     1 0 2 my $self = shift;
31 1         7 $self->SUPER::init( "body" );
32 1 50       6 $self->initTimeline() unless $par_bug;
33             }
34              
35             sub initTimeline {
36 1     1 0 2 my $self = shift;
37 1         3 my $array_ref = [];
38 1         3 $self->{$timelineStack} = $array_ref;
39            
40             # Removed to fix first Par bug
41 1 50       3 if( !$par_bug ) {
42 0         0 my $par = new SMIL::Par;
43 0         0 push @{$self->{$timelineStack}}, $par;
  0         0  
44 0         0 $self->setTagContents( $timeline => $par );
45             }
46             else {
47 1         2 my $tag = shift;
48 1         3 push @{$self->{$timelineStack}}, $tag;
  1         3  
49 1         6 $self->setTagContents( $timeline => $tag );
50             }
51             }
52              
53             sub startSequence {
54 1     1 0 3 my $self = shift;
55 1         16 my $seq = new SMIL::Seq( @_ );
56 1 50 33     6 if( !$par_bug || @{$self->{$timelineStack}} ) {
  1         14  
57 1         2 ${$self->{$timelineStack}}[ -1 ]->setTagContents( $self->{$counter}++ => $seq );
  1         15  
58 1         2 push @{$self->{$timelineStack}}, $seq;
  1         3  
59             }
60             else {
61 0         0 $self->initTimeline( $seq );
62             }
63 1 50       2 croak "Timeline not there\n" unless @{$self->{$timelineStack}};
  1         10  
64             }
65              
66             sub startParallel {
67 0     0 0 0 my $self = shift;
68 0         0 my $par = new SMIL::Par( @_ );
69 0 0 0     0 if( !par_bug || @{$self->{$timelineStack}} ) {
  0         0  
70 0         0 ${$self->{$timelineStack}}[ -1 ]->setTagContents( $self->{$counter}++ => $par );
  0         0  
71 0         0 push @{$self->{$timelineStack}}, $par;
  0         0  
72             }
73             else {
74 0         0 $self->initTimeline( $par );
75             }
76            
77 0         0 if( 0 ) {
78             ${$self->{$timelineStack}}[ -1 ]->setTagContents( $self->{$counter}++ => $par );
79             push @{$self->{$timelineStack}}, $par;
80             }
81              
82 0 0       0 croak "Timeline not there \n" unless @{$self->{$timelineStack}};
  0         0  
83             }
84              
85             sub endParallel {
86 0     0 0 0 my $self = shift;
87 0         0 my $top = pop @{$self->{$timelineStack}};
  0         0  
88 0 0 0     0 croak "Bad timeline: make sure that start and end functions match.\n"
      0        
89             if $check_errors && ( !$top || $top->getTag() ne $PAR );
90             }
91              
92             sub endSequence {
93 1     1 0 3 my $self = shift;
94 1         2 my $top = pop @{$self->{$timelineStack}};;
  1         3  
95 1 0 0     6 croak "Bad timeline: make sure that add and end functions match.\n"
      33        
96             if $check_errors && ( !$top || $top->getTag() ne $SEQ );
97             }
98              
99             # Strictly for debugging
100             sub printTimelineStack {
101 0     0 0 0 foreach $item ( @{$self->{$timelineStack}} ) {
  0         0  
102 0         0 print "$item\n";
103             }
104             }
105              
106             sub addMedia {
107 3     3 0 4 my $self = shift;
108 3         9 my %hash = @_;
109            
110 2         9 $self->initTimeline( new SMIL::Par )
111 3 100 66     23 unless( $self->{$timelineStack} && @{$self->{$timelineStack}} );
112 3         8 croak "Need to call startParallel or startSequence before adding media\n"
113 3 50 33     12 if !$check_errors && !@{$self->{$timelineStack}};
114            
115 3         6 my $timeline_head = ${$self->{$timelineStack}}[ -1 ];
  3         7  
116 3         14 my $media = &getMediaObject( @_ );
117 3         16 $timeline_head->setTagContents( $self->{$counter}++ => $media );
118             }
119              
120             sub addCode {
121 2     2 0 4 my $self = shift;
122 2         5 my $code = shift;
123            
124 2 50 33     10 if( $self->{$timelineStack} && @{$self->{$timelineStack}} ) {
  2         10  
125 2         3 my $timeline_head = ${$self->{$timelineStack}}[ -1 ];
  2         6  
126 2         23 my $media = new SMIL::Code( $code );
127 2         10 $timeline_head->setTagContents( $self->{$counter}++ => $media );
128             }
129             else {
130 0         0 $self->initTimeline( new SMIL::Code( $code ) );
131             }
132             }
133              
134              
135             sub addSwitchedMedia {
136 1     1 0 2 my $self = shift;
137 1         4 my %hash = @_;
138            
139             # Extract the switch attribute
140 1         3 my $switch_attribute = $hash{ $switch };
141 1         2 my $media = $hash{ $medias };
142            
143 1         16 $self->initTimeline( new SMIL::Par )
144 1 50 33     5 unless( $self->{$timelineStack} && @{$self->{$timelineStack}} );
145 1         4 croak "Need to call startParallel or startSequence before adding media\n"
146 1 50 33     5 if !$check_errors && !@{$self->{$timelineStack}};
147            
148 1         11 my $switch_obj = new SMIL::Switch( $switch_attribute, $media );
149 1         2 my $timeline_head = ${$self->{$timelineStack}}[ -1 ];
  1         4  
150 1         10 $timeline_head->setTagContents( $self->{$counter}++ => $switch_obj );
151              
152             }
153              
154