| 1 | package Text::Livedoor::Wiki::Plugin::Function::Image; | ||||||||||||||||||||||
| 2 | 11 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 11 | ▶ | use base qw/Text::Livedoor::Wiki::Plugin::Function/; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | 11 | ▶ | use Text::Livedoor::Wiki::Utils; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | 11 | __PACKAGE__->function_name('ref'); | |||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | 16 | ▶ | sub prepare_args { | ||||||||||||||||||||
|
Subroutine
prepare_args: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||
| 9 | 16 | my $class= shift; | |||||||||||||||||||||
| 10 | 16 | my $args = shift; | |||||||||||||||||||||
| 11 | 16 | my $my_args = {}; | |||||||||||||||||||||
| 12 | |||||||||||||||||||||||
| 13 | # no args | ||||||||||||||||||||||
| 14 | 16 | ▶ | die 'no args' unless scalar @$args; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 15 | |||||||||||||||||||||||
| 16 | # image url | ||||||||||||||||||||||
| 17 | 15 | my $image_url = $args->[0]; | |||||||||||||||||||||
| 18 | 15 | ▶ | die 'not image url' unless Text::Livedoor::Wiki::Utils::is_image_url( $image_url ); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 19 | 14 | $my_args->{url} = $image_url; | |||||||||||||||||||||
| 20 | |||||||||||||||||||||||
| 21 | # width , heigth , align | ||||||||||||||||||||||
| 22 | 14 | my $flg = 0; | |||||||||||||||||||||
| 23 | 14 | for(@$args) { | |||||||||||||||||||||
| 24 | 38 | ▶ | if ( $_ =~ /^\d+$/ ) { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 25 | 15 | ▶ | if($flg ==0 ){ | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 26 | 8 | $my_args->{width} = $_; | |||||||||||||||||||||
| 27 | 8 | $flg =1; | |||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||
| 29 | elsif( $flg == 1 ) { | ||||||||||||||||||||||
| 30 | 6 | $my_args->{height} = $_; | |||||||||||||||||||||
| 31 | 6 | $flg++; | |||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||
| 34 | elsif( $_ eq '' ) { | ||||||||||||||||||||||
| 35 | 1 | ▶ | $flg = 1 if $flg == 0; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||
| 37 | elsif( $_ =~ /^left|right$/i ) { | ||||||||||||||||||||||
| 38 | 7 | $my_args->{align} = lc $_; | |||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||
| 40 | elsif( $_ eq 'no_link' ) { | ||||||||||||||||||||||
| 41 | 1 | $my_args->{no_link} = 1; | |||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||
| 44 | 14 | return $my_args; | |||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||
| 46 | 14 | ▶ | sub prepare_value { | ||||||||||||||||||||
|
Subroutine
prepare_value: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 47 | 14 | my $class= shift; | |||||||||||||||||||||
| 48 | 14 | ▶ | my $value = shift || ''; | ||||||||||||||||||||
|
Condition100%2/2
shift() || ''
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||
| 49 | 14 | return Text::Livedoor::Wiki::Utils::escape( $value ); | |||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||
| 51 | |||||||||||||||||||||||
| 52 | 14 | ▶ | sub process { | ||||||||||||||||||||
|
Subroutine
process: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||
| 53 | 14 | my ( $class, $inline, $data ) = @_; | |||||||||||||||||||||
| 54 | 14 | my $args = $data->{args}; | |||||||||||||||||||||
| 55 | 14 | my $value = $data->{value}; | |||||||||||||||||||||
| 56 | |||||||||||||||||||||||
| 57 | # build attr | ||||||||||||||||||||||
| 58 | 14 | ▶ | my $width = exists $args->{width} ? ' width="' . $args->{width} . '"' : ''; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 59 | 14 | ▶ | my $height = exists $args->{height} ? ' height="' . $args->{height} . '"' : ''; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 60 | 14 | ▶ | my $alt = length($value) ? ' alt="' . $value . '"' : ''; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 61 | 14 | ▶ | my $align = exists $args->{align} ? ' align="' . $args->{align} . '"' : ''; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 62 | |||||||||||||||||||||||
| 63 | # done | ||||||||||||||||||||||
| 64 | 14 | ▶ | if( $args->{no_link} ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 65 | 1 | return sprintf( '<img src="%s" border="0"%s%s%s%s />' , $data->{args}{url} , $width,$height,$alt,$align ); | |||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||
| 67 | else { | ||||||||||||||||||||||
| 68 | 13 | return sprintf( '<a href="%s"><img src="%s" border="0"%s%s%s%s /></a>' , $data->{args}{url} ,$data->{args}{url} , $width,$height,$alt,$align ); | |||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||
| 70 | |||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||
| 72 | |||||||||||||||||||||||
| 73 | 11 | 1; | |||||||||||||||||||||
| 74 | |||||||||||||||||||||||
| 75 | =head1 NAME | ||||||||||||||||||||||
| 76 | |||||||||||||||||||||||
| 77 | Text::Livedoor::Wiki::Plugin::Function::Image - Image Function Plugin | ||||||||||||||||||||||
| 78 | |||||||||||||||||||||||
| 79 | =head1 DESCRIPTION | ||||||||||||||||||||||
| 80 | |||||||||||||||||||||||
| 81 | put your picture everywhere! | ||||||||||||||||||||||
| 82 | |||||||||||||||||||||||
| 83 | =head1 SYNOPSIS | ||||||||||||||||||||||
| 84 | |||||||||||||||||||||||
| 85 | &ref(http://image.profile.livedoor.jp/icon/polocky_60.gif) | ||||||||||||||||||||||
| 86 | &ref(http://image.profile.livedoor.jp/icon/polocky_60.gif){hoge hoge"'><} | ||||||||||||||||||||||
| 87 | &ref(http://image.profile.livedoor.jp/icon/polocky_60.gif,10,10,left) | ||||||||||||||||||||||
| 88 | &ref(http://image.profile.livedoor.jp/icon/polocky_60.gif,left,10,10) | ||||||||||||||||||||||
| 89 | &ref(http://image.profile.livedoor.jp/icon/polocky_60.gif,left,10) | ||||||||||||||||||||||
| 90 | &ref(http://image.profile.livedoor.jp/icon/polocky_60.gif,10) | ||||||||||||||||||||||
| 91 | |||||||||||||||||||||||
| 92 | =head1 FUNCTION | ||||||||||||||||||||||
| 93 | |||||||||||||||||||||||
| 94 | =head2 prepare_args | ||||||||||||||||||||||
| 95 | |||||||||||||||||||||||
| 96 | =head2 prepare_value | ||||||||||||||||||||||
| 97 | |||||||||||||||||||||||
| 98 | =head2 process | ||||||||||||||||||||||
| 99 | |||||||||||||||||||||||
| 100 | =head1 AUTHOR | ||||||||||||||||||||||
| 101 | |||||||||||||||||||||||
| 102 | polocky | ||||||||||||||||||||||
| 103 | |||||||||||||||||||||||
| 104 | =cut | ||||||||||||||||||||||