line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Video::Embed; |
2
|
11
|
|
|
11
|
|
308266
|
use Moo; |
|
11
|
|
|
|
|
214867
|
|
|
11
|
|
|
|
|
75
|
|
3
|
|
|
|
|
|
|
|
4
|
11
|
|
|
11
|
|
34734
|
use URI; |
|
11
|
|
|
|
|
95351
|
|
|
11
|
|
|
|
|
353
|
|
5
|
11
|
|
|
11
|
|
9950
|
use URI::QueryParam; |
|
11
|
|
|
|
|
8226
|
|
|
11
|
|
|
|
|
296
|
|
6
|
11
|
|
|
11
|
|
9842
|
use URI::Escape::XS; |
|
11
|
|
|
|
|
46983
|
|
|
11
|
|
|
|
|
1276
|
|
7
|
|
|
|
|
|
|
|
8
|
11
|
|
|
11
|
|
16073
|
use Data::Validate::URI qw/is_web_uri/; |
|
11
|
|
|
|
|
679743
|
|
|
11
|
|
|
|
|
726
|
|
9
|
11
|
|
|
11
|
|
10093
|
use Module::Find; |
|
11
|
|
|
|
|
14925
|
|
|
11
|
|
|
|
|
4701
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.015003'; |
12
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'class' => ( |
15
|
|
|
|
|
|
|
'is' => 'rw', |
16
|
|
|
|
|
|
|
'required' => 1, |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has '_modules' => ( |
20
|
|
|
|
|
|
|
'is' => 'ro', |
21
|
|
|
|
|
|
|
'init_arg' => undef, |
22
|
|
|
|
|
|
|
'builder' => '_build__modules', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _build__modules{ |
26
|
11
|
|
|
11
|
|
14069
|
my ( $self ) = @_; |
27
|
|
|
|
|
|
|
|
28
|
11
|
|
|
|
|
44
|
my $namespace = ref( $self ) . "::Site"; |
29
|
|
|
|
|
|
|
|
30
|
11
|
|
|
|
|
76
|
my @mods = useall( $namespace ); |
31
|
|
|
|
|
|
|
|
32
|
11
|
|
|
|
|
389
|
my $modules = {}; |
33
|
11
|
|
|
|
|
33
|
foreach my $mod ( @mods ){ |
34
|
121
|
|
|
|
|
1167
|
my $module = $mod->new; |
35
|
121
|
|
|
|
|
112312
|
$modules->{ $module->domain_reg } = $module; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
11
|
|
|
|
|
354
|
return $modules; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub url_to_embed{ |
42
|
57
|
|
|
57
|
1
|
309
|
my ( $self, $url ) = @_; |
43
|
|
|
|
|
|
|
|
44
|
57
|
|
|
|
|
175
|
my ( $domain_reg, $uri ) = $self->_is_video( $url ); |
45
|
57
|
100
|
|
|
|
745
|
if ( defined( $domain_reg ) ){ |
46
|
45
|
|
|
|
|
270
|
return $self->_modules->{ $domain_reg }->process( $self, $uri ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
12
|
|
|
|
|
59
|
return undef; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _is_video{ |
53
|
57
|
|
|
57
|
|
113
|
my ( $self, $url ) = @_; |
54
|
|
|
|
|
|
|
|
55
|
57
|
100
|
|
|
|
2825
|
return undef if ( !is_web_uri($url) ); |
56
|
|
|
|
|
|
|
|
57
|
56
|
|
|
|
|
46450
|
my $uri = URI->new( URI::Escape::XS::uri_unescape($url) ); |
58
|
|
|
|
|
|
|
|
59
|
56
|
|
|
|
|
122204
|
foreach my $domain_reg ( keys(%{ $self->_modules }) ){ |
|
56
|
|
|
|
|
440
|
|
60
|
|
|
|
|
|
|
#figure out if url is supported |
61
|
376
|
100
|
|
|
|
17745
|
if ( $uri->host =~ m/$domain_reg/ ){ |
62
|
45
|
|
|
|
|
1249
|
return ( $domain_reg, $uri ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
11
|
|
|
|
|
312
|
return undef; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 NAME |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
HTML::Video::Embed - convert a url into a html embed string |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 SYNOPSIS |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
#css |
78
|
|
|
|
|
|
|
.css-video-class{ |
79
|
|
|
|
|
|
|
width:570px; |
80
|
|
|
|
|
|
|
height:340px; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
#perl |
84
|
|
|
|
|
|
|
use HTML::Video::Embed; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $embedder = HTML::Video::Embed->new({ |
87
|
|
|
|
|
|
|
'class' => 'css-video-class', |
88
|
|
|
|
|
|
|
}); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $url = 'http://www.youtube.com/watch?v=HMhks1TSFog'; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
my $html_embed_code = $embedder->url_to_embed( $url ); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$html_embed_code is now == "" |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
my $url = 'http://this.is.not/a_supported-video_url'; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $html_embed_code = $embedder->url_to_embed( $url ); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
$html_embed_code is now == undef |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 DESCRIPTION |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Converts urls into html embed codes, supported sites are |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Collegehumor |
108
|
|
|
|
|
|
|
DailyMotion |
109
|
|
|
|
|
|
|
EbaumsWorld |
110
|
|
|
|
|
|
|
FunnyOrDie |
111
|
|
|
|
|
|
|
Kontraband |
112
|
|
|
|
|
|
|
LiveLeak |
113
|
|
|
|
|
|
|
MetaCafe |
114
|
|
|
|
|
|
|
Vimeo |
115
|
|
|
|
|
|
|
YahooScreen |
116
|
|
|
|
|
|
|
Youtube |
117
|
|
|
|
|
|
|
Youtu.be |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 METHODS |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 new |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Takes one argument, class, which sets the css class of the video |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 url_to_embed |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
converts a url into the html embed code |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
returns html on success, or undef if not supported |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 AUTHORS |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Mark Ellis Emarkellis@cpan.orgE |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 SEE ALSO |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
L |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 LICENSE |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Copyright 2014 Mark Ellis Emarkellis@cpan.orgE |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify |
144
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |