line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Video::Embed; |
2
|
9
|
|
|
9
|
|
150201
|
use Moo; |
|
9
|
|
|
|
|
103479
|
|
|
9
|
|
|
|
|
43
|
|
3
|
|
|
|
|
|
|
|
4
|
9
|
|
|
9
|
|
15809
|
use URI; |
|
9
|
|
|
|
|
48528
|
|
|
9
|
|
|
|
|
228
|
|
5
|
9
|
|
|
9
|
|
3955
|
use URI::QueryParam; |
|
9
|
|
|
|
|
4816
|
|
|
9
|
|
|
|
|
223
|
|
6
|
9
|
|
|
9
|
|
4314
|
use URI::Escape::XS; |
|
9
|
|
|
|
|
22946
|
|
|
9
|
|
|
|
|
710
|
|
7
|
|
|
|
|
|
|
|
8
|
9
|
|
|
9
|
|
4339
|
use Data::Validate::URI qw/is_web_uri/; |
|
9
|
|
|
|
|
359672
|
|
|
9
|
|
|
|
|
534
|
|
9
|
9
|
|
|
9
|
|
4623
|
use Module::Find; |
|
9
|
|
|
|
|
8802
|
|
|
9
|
|
|
|
|
1322
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.016000'; |
12
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has class => ( |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
required => 1, |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has secure => ( |
20
|
|
|
|
|
|
|
is => 'ro', |
21
|
|
|
|
|
|
|
default => 0, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has _modules => ( |
25
|
|
|
|
|
|
|
is => 'ro', |
26
|
|
|
|
|
|
|
init_arg => undef, |
27
|
|
|
|
|
|
|
builder => '_build__modules', |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _build__modules{ |
31
|
10
|
|
|
10
|
|
10074
|
my ( $self ) = @_; |
32
|
|
|
|
|
|
|
|
33
|
10
|
|
|
|
|
35
|
my $namespace = ref( $self ) . "::Site"; |
34
|
|
|
|
|
|
|
|
35
|
10
|
|
|
|
|
50
|
my @mods = useall( $namespace ); |
36
|
|
|
|
|
|
|
|
37
|
10
|
|
|
|
|
4655
|
my $modules = {}; |
38
|
10
|
|
|
|
|
28
|
MODULES: foreach my $mod ( @mods ){ |
39
|
|
|
|
|
|
|
{ |
40
|
9
|
|
|
9
|
|
49
|
no warnings 'uninitialized'; |
|
9
|
|
|
|
|
10
|
|
|
9
|
|
|
|
|
2454
|
|
|
90
|
|
|
|
|
80
|
|
41
|
90
|
50
|
|
|
|
3532
|
next MODULES if $VERSION != eval "\$${mod}::VERSION"; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
90
|
|
|
|
|
557
|
my $module = $mod->new; |
45
|
90
|
|
|
|
|
1904
|
$modules->{ $module->domain_reg } = $module; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
10
|
|
|
|
|
255
|
return $modules; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub url_to_embed{ |
52
|
50
|
|
|
50
|
1
|
250
|
my ( $self, $url ) = @_; |
53
|
|
|
|
|
|
|
|
54
|
50
|
|
|
|
|
114
|
my ( $domain_reg, $uri ) = $self->_is_video( $url ); |
55
|
50
|
100
|
|
|
|
544
|
if ( defined( $domain_reg ) ){ |
56
|
40
|
|
|
|
|
208
|
return $self->_modules->{ $domain_reg }->process( $self, $uri ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
10
|
|
|
|
|
42
|
return undef; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _is_video{ |
63
|
50
|
|
|
50
|
|
59
|
my ( $self, $url ) = @_; |
64
|
|
|
|
|
|
|
|
65
|
50
|
100
|
|
|
|
1219
|
return undef if ( !is_web_uri($url) ); |
66
|
|
|
|
|
|
|
|
67
|
49
|
|
|
|
|
27894
|
my $uri = URI->new( URI::Escape::XS::uri_unescape($url) ); |
68
|
|
|
|
|
|
|
|
69
|
49
|
|
|
|
|
61147
|
foreach my $domain_reg ( keys(%{ $self->_modules }) ){ |
|
49
|
|
|
|
|
275
|
|
70
|
|
|
|
|
|
|
#figure out if url is supported |
71
|
286
|
100
|
|
|
|
6547
|
if ( $uri->host =~ m/$domain_reg/ ){ |
72
|
40
|
|
|
|
|
1024
|
return ( $domain_reg, $uri ); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
9
|
|
|
|
|
216
|
return undef; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 NAME |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
HTML::Video::Embed - convert a url into a html embed string |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 SYNOPSIS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
#css |
88
|
|
|
|
|
|
|
.css-video-class{ |
89
|
|
|
|
|
|
|
width:570px; |
90
|
|
|
|
|
|
|
height:340px; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#perl |
94
|
|
|
|
|
|
|
use HTML::Video::Embed; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
my $embedder = HTML::Video::Embed->new({ |
97
|
|
|
|
|
|
|
class => 'css-video-class', |
98
|
|
|
|
|
|
|
secure => 1 |
99
|
|
|
|
|
|
|
}); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $url = 'http://www.youtube.com/watch?v=HMhks1TSFog'; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $html_embed_code = $embedder->url_to_embed( $url ); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$html_embed_code is now == "" |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $url = 'http://this.is.not/a_supported-video_url'; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my $html_embed_code = $embedder->url_to_embed( $url ); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
$html_embed_code is now == undef |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 DESCRIPTION |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Converts urls into html embed codes, supported sites are |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Collegehumor |
119
|
|
|
|
|
|
|
DailyMotion |
120
|
|
|
|
|
|
|
EbaumsWorld |
121
|
|
|
|
|
|
|
FunnyOrDie |
122
|
|
|
|
|
|
|
Kontraband |
123
|
|
|
|
|
|
|
LiveLeak |
124
|
|
|
|
|
|
|
MetaCafe |
125
|
|
|
|
|
|
|
Vimeo |
126
|
|
|
|
|
|
|
YahooScreen |
127
|
|
|
|
|
|
|
Youtube |
128
|
|
|
|
|
|
|
Youtu.be |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 METHODS |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 new |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Takes two arguments |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head3 class |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sets the css class of the video |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head3 secure |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
if true, will return a url with the https scheme, or undef if the site doesn't support secure embedding |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 url_to_embed |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
converts a url into the html embed code |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
returns html on success, or undef if not supported |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 AUTHORS |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Mark Ellis Emarkellis@cpan.orgE |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 SEE ALSO |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
L |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 LICENSE |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Copyright 2014 Mark Ellis Emarkellis@cpan.orgE |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify |
163
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |