line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SMIL::MediaResolver; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = "0.898"; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
my %typeLookupHash = ( |
6
|
|
|
|
|
|
|
'smil' => 'application/smil', |
7
|
|
|
|
|
|
|
'rt' => 'text/vnd.rn-realtext', |
8
|
|
|
|
|
|
|
'rp' => 'image/vnd.rn-realpix', |
9
|
|
|
|
|
|
|
'swf' => 'image/vnd.rn-realflash', |
10
|
|
|
|
|
|
|
'gif' => 'image/gif', |
11
|
|
|
|
|
|
|
'jpg' => 'image/jpeg', |
12
|
|
|
|
|
|
|
'jpeg' => 'image/jpeg', |
13
|
|
|
|
|
|
|
'rm' => 'audio/vnd.rn-realvideo', |
14
|
|
|
|
|
|
|
'ra' => 'audio/vnd.rn-realvideo', |
15
|
|
|
|
|
|
|
'txt' => 'text/plain', |
16
|
|
|
|
|
|
|
'html' => 'text/html', |
17
|
|
|
|
|
|
|
'htm' => 'text/html', |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub resolveTypeFromUrl { |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
0
|
0
|
|
my $type = ""; |
24
|
0
|
|
|
|
|
|
my $url = shift; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
@results = &LWP::Simple::head( $url ); |
27
|
0
|
|
|
|
|
|
$type = $results[ 0 ]; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
return $type; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub getContent { |
34
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
eval 'use LWP::Simple;'; |
37
|
0
|
|
|
|
|
|
my $lwpInstalled = !$@; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $content = ""; |
40
|
0
|
|
|
|
|
|
my $type = ""; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $thisSrc = $self->getAttribute( "src" ); |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
if( ref( $thisSrc ) ) { |
|
|
0
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# I cannot figure out how to define an interface base class |
46
|
|
|
|
|
|
|
# and then derive all my concrete classes from it and |
47
|
|
|
|
|
|
|
# maintain the interface transparently. So, just eval |
48
|
|
|
|
|
|
|
# the function call on this object and if it fails, well, it |
49
|
|
|
|
|
|
|
# obviously wasn't the proper type. |
50
|
0
|
|
|
|
|
|
eval { |
51
|
0
|
|
|
|
|
|
$content = $thisSrc->getAsString(); |
52
|
0
|
|
|
|
|
|
$type = $thisSrc->getMimeType(); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
}; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif( $thisSrc ) { |
58
|
0
|
0
|
0
|
|
|
|
if( $thisSrc =~ /^http:/ and $lwpInstalled ) { |
|
|
0
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$content = &LWP::Simple::get( $thisSrc ); |
60
|
0
|
|
|
|
|
|
$type = &resolveTypeFromUrl( $thisSrc ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
elsif( $thisSrc !~ /^http:/ ) { |
63
|
|
|
|
|
|
|
# Assume it comes from disk |
64
|
0
|
0
|
|
|
|
|
if( open CONTENT, $thisSrc ) { |
65
|
0
|
|
|
|
|
|
binmode CONTENT; |
66
|
0
|
|
|
|
|
|
undef $/; |
67
|
0
|
|
|
|
|
|
$content = ; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Lookup the type based on filename |
71
|
0
|
|
|
|
|
|
$type = &lookupType( $thisSrc ); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
return( $content, $type ); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub lookupType { |
79
|
0
|
|
|
0
|
0
|
|
my $filename = shift; |
80
|
|
|
|
|
|
|
# get filename extension |
81
|
0
|
0
|
|
|
|
|
$extension = $1 if $filename =~ /\.(.*?)$/; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Lowercase it |
84
|
0
|
|
|
|
|
|
$extension = "\L$extension"; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
return $typeLookupHash{ $extension }; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|