| 1 | package MojoMojo::Formatter::YouTube; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 26 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 26 | ▶ | use parent 'MojoMojo::Formatter'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 26 | eval {require URI::Fetch}; | |||||||||||||||||||||||||||
| 7 | 26 | my $dependencies_installed = !$@; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head2 module_loaded | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | Return true if the module is loaded. | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =cut | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub module_loaded { $dependencies_installed } | ||||||||||||||||||||||||||
|
Subroutine
module_loaded: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 26 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head1 NAME | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | MojoMojo::Formatter::YouTube - Embed YouTube player | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | Embed YouTube video player for given video by writing {{youtube <url>}}. | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head1 METHODS | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head2 format_content_order | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | Format order can be 1-99. The YouTube formatter runs on 10. | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =cut | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 744 | ▶ | sub format_content_order { 10 } | ||||||||||||||||||||||||||
|
Subroutine
format_content_order: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =head2 format_content | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | Calls the formatter. Takes a ref to the content as well as the | ||||||||||||||||||||||||||||
| 40 | context object. | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =cut | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 129 | ▶ | sub format_content { | ||||||||||||||||||||||||||
|
Subroutine
format_content: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 129 | my ( $class, $content, $c ) = @_; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 129 | my @lines = split /\n/, $$content; | |||||||||||||||||||||||||||
| 48 | 129 | $$content = ""; | |||||||||||||||||||||||||||
| 49 | 129 | my $re = $class->gen_re(qr/youtube\s+(.*?)/); | |||||||||||||||||||||||||||
| 50 | 129 | ▶ | my $lang = $c->sessionid ? $c->session->{lang} : $c->pref('default_lang') || 'en'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$c->pref("default_lang") or "en"
MC/DC100%1/1
$c->pref("default_lang") or "en"
$c->pref("default_lang")
Truth table100%2/2
A
A= $c->pref("default_lang")
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 129 | foreach my $line (@lines) { | |||||||||||||||||||||||||||
| 53 | 664 | ▶ | if ( $line =~ m/$re/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 5 | $line = $class->process($c, $line, $re, $lang); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 664 | $$content .= $line . "\n"; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head2 process | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | Do the meat of inserting a youtube movie into a wiki page. | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =cut | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 5 | ▶ | sub process { | ||||||||||||||||||||||||||
|
Subroutine
process: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | 5 | my ( $class, $c, $line, $re, $lang) = @_; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 5 | my $youtube = $c->loc('YouTube Video'); | |||||||||||||||||||||||||||
| 71 | 5 | my $video_id; | |||||||||||||||||||||||||||
| 72 | 5 | $line =~ m/$re/; | |||||||||||||||||||||||||||
| 73 | 5 | my $url = URI->new($1); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 5 | ▶ | unless ($url){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | $line =~ s/$re/"$youtube: $url ".$c->loc('is not a valid url')/e; | |||||||||||||||||||||||||||
| 77 | 0 | return $line; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 5 | ▶ | if ($url =~ m!youtube.com/.*?v=([A-Za-z0-9_-]+)!){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 4 | $video_id=$1; | |||||||||||||||||||||||||||
| 82 | } else { | ||||||||||||||||||||||||||||
| 83 | 1 | $line =~ s/$re/"$youtube: $url ".$c->loc('is not a valid link to youtube video')/e; | |||||||||||||||||||||||||||
| 84 | 1 | return $line; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 4 | ▶ | if ( ($c->action->reverse eq 'pageadmin/edit') || ($c->action->reverse eq 'jsrpc/render') ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$c->action->reverse eq "pageadmin/edit" or $c->action->reverse eq "jsrpc/render"
MC/DC100%2/2
$c->action->reverse eq "pageadmin/edit" or $c->action->reverse eq "jsrpc/render"
$c->action->reverse eq "pageadmin/edit"
$c->action->reverse eq "jsrpc/render"
Truth table100%3/3
A or B
A= $c->action->reverse eq "pageadmin/edit"B= $c->action->reverse eq "jsrpc/render"
| |||||||||||||||||||||||||||||
| 88 | 3 | $line =~ s!$re!<div style='width: 425px;height: 344px; border: 1px black dotted;'>$youtube<br /><a href="$url">$url</a></div>!; | |||||||||||||||||||||||||||
| 89 | 3 | $c->stash->{precompile_off} = 1; | |||||||||||||||||||||||||||
| 90 | } else { | ||||||||||||||||||||||||||||
| 91 | 1 | $line =~ s!$re!<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/$video_id&hl=$lang"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/$video_id&hl=$lang" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>!; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 4 | return $line; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | L<MojoMojo>, L<Module::Pluggable::Ordered>, L<URI::Fetch> | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | Robert 'LiNiO' Litwiniec <linio@wonder.pl> | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | This library is free software. You can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 107 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =cut | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 26 | 1; | |||||||||||||||||||||||||||