File Coverage

blib/lib/SMIL/UnanchoredMedia.pm
Criterion Covered Total %
statement 22 32 68.7
branch 6 12 50.0
condition 2 3 66.6
subroutine 5 5 100.0
pod 0 2 0.0
total 35 54 64.8


line stmt bran cond sub pod time code
1             package SMIL::UnanchoredMedia;
2              
3             $VERSION = "0.898";
4              
5 1     1   6 use SMIL::XMLTag;
  1         2  
  1         103  
6 1     1   6 use SMIL::MediaAttributes;
  1         3  
  1         193  
7 1     1   2009 use SMIL::MediaResolver;
  1         3  
  1         542  
8              
9             @ISA = qw( SMIL::XMLTag SMIL::MediaResolver );
10              
11             my $media_type = 'type';
12             my $INLINE = 'inline';
13              
14             sub init {
15 4     4 0 5 my $self = shift;
16 4         13 my %hash = @_;
17            
18 4         6 my $type = "";
19 4 100 66     21 $type = $hash{ $media_type }
20             unless ( !$hash{ $media_type } or
21             $hash{ $media_type } =~ /.\/./ );
22 4 100       21 $self->SUPER::init( $type ? $type : "ref" );
23            
24 4 50       12 if( $hash{ $INLINE } ) {
25 0         0 $self->{_inline} = 1;
26             }
27            
28 4         172 my %attrs = $self->createValidAttributes( { %hash },
29             [@mediaAttributes] );
30            
31 4         28 $self->setAttributes( %attrs );
32 4         22 $self->setFavorite( "src" );
33             }
34              
35             sub getAsString {
36            
37 4     4 0 6 my $self = shift;
38 4         5 my $content = "";
39            
40 4 50       13 if( $self->{_inline} ) {
41 0         0 eval 'use MIME::Base64';
42 0         0 my $canEncode = !$@;
43            
44 0 0       0 if( $canEncode ) {
45             # OK, download the media, or whatever and Base64 encode it.
46 0         0 my( $content, $type ) = $self->getContent;
47            
48             # encode it
49 0         0 $content = &encode_base64( $content );
50 0         0 chomp $content;
51            
52 0 0       0 if( $content ) {
53             # tack on the type
54 0         0 $content = "data:$type;base64,$content";
55            
56 0         0 $self->setAttribute( "src" => $content );
57             }
58             }
59             }
60            
61 4         16 return $self->SUPER::getAsString;
62             }
63              
64             1;