Wiki/Plugin/Function/Image.pm

filter: Statementstmt 100% 46 / 46 Branchbran 96.4% 27 / 28 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 98.8% 86 / 87 CC 17 SCAR 19.7
CC
17
Cov
99%
prepare_args
11.0
process
6.0
prepare_value
2.0
CRAP 7.2
« Wiki/Plugin/Block/H5.pm ↑ Summary Wiki/Plugin/Block/H3.pm »
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
BranchTrueFalseTotal
unless scalar @$args 1 15 16
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
BranchTrueFalseTotal
unless Text::Livedoor::Wiki::Utils::is_image_url($image_url) 1 14 15
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
BranchTrueFalseTotal
if ($_ =~ /^\d+$/) { } 15 23 38
elsif ($_ eq '') { } 1 22 23
elsif ($_ =~ /^left|right$/i) { } 7 15 22
elsif ($_ eq 'no_link') { } 1 14 15
25 15 ▶ if($flg ==0 ){
Branch: 2 branches
BranchTrueFalseTotal
if ($flg == 0) { } 8 7 15
elsif ($flg == 1) { } 6 1 7
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
BranchTrueFalseTotal
if $flg == 0 1 0 1
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() || ''
l!l
212
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
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
BranchTrueFalseTotal
exists $args->{'width'} ? : 8 6 14
59 14 ▶ my $height = exists $args->{height} ? ' height="' . $args->{height} . '"' : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'height'} ? : 6 8 14
60 14 ▶ my $alt = length($value) ? ' alt="' . $value . '"' : '';
Branch: 1 branch
BranchTrueFalseTotal
length $value ? : 2 12 14
61 14 ▶ my $align = exists $args->{align} ? ' align="' . $args->{align} . '"' : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'align'} ? : 7 7 14
62
63 # done
64 14 ▶ if( $args->{no_link} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'no_link'}) { } 1 13 14
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
« Wiki/Plugin/Block/H5.pm ↑ Summary Wiki/Plugin/Block/H3.pm »