Wiki/Utils.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 12 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 6 / 6 totaltotal 100% 62 / 62 CC 7 SCAR 8.9
CC
7
Cov
100%
get_width_height
4.0
is_image_url
3.0
is_url
2.0
CRAP 2.4
« Wiki/Plugin/Inline/WikiPage.pm ↑ Summary Wiki/Plugin.pm »
1 package Text::Livedoor::Wiki::Utils;
2 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 499 ▶sub escape {
Subroutine escape: called CC=1 SCAR=0.0
Pod documented
6 499 my $str = shift;
7  
8 #$str =~ s/&/&/g; allow user to use html escape.
9 499 $str =~ s/</&lt;/g;
10 499 $str =~ s/>/&gt;/g;
11 499 $str =~ s/"/&quot;/g;
12  
13 499 return $str;
14  
15 }
16  
17 43 ▶sub escape_more {
Subroutine escape_more: called CC=1 SCAR=0.0
Pod documented
18 43 my $str = shift;
19 43 $str =~ s/&/&amp;/g;
20 43 $str =~ s/#/&#35;/g; # for #contents
21 43 return escape( $str );
22 }
23  
24 2 ▶sub sanitize_uri {
Subroutine sanitize_uri: called CC=1 SCAR=0.0
Pod documented
25 2 my $str = shift;
26 2 $str =~ s/^\s+//;
27 2 $str =~ s/\s+$//;
28 2 $str
29 12 =~ s/([^A-Za-z0-9;\/\?\:\@\&\=\+\$,\[\]\-\_\.\!\~\*\'\(\)%\#])/'%'.unpack('H2', $1)/eg;
30 2 return $str;
31 }
32  
33 35 ▶sub is_image_url {
Subroutine is_image_url: called CC=3 SCAR=11.0
Pod documented
34 35 my $url = shift;
35 35 ▶ return unless &is_url( $url );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_url($url) 6 29 35
36 # bmp >_<
37 29 ▶ return $url =~ /\.(jpg|jpeg|png|gif|bmp)(\?.*|#.*)?$/i ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$url =~ /\.(jpg|jpeg|png|gif|bmp)(\?.*|#.*)?$/i ? : 18 11 29
38 }
39 35 ▶sub is_url {
Subroutine is_url: called CC=2 SCAR=6.9
Pod documented
40 35 my $url = shift;
41 35 ▶ return $url =~ /^(?:http|https|ftp):\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+$/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$url =~ m[^(?:http|https|ftp)://[-_.!~*'()a-zA-Z0-9;/?:\@&=+\$,%#]+$] ? : 29 6 35
42 }
43  
44 30 ▶sub get_width_height {
Subroutine get_width_height: called CC=4 SCAR=13.9
Pod documented
45 30 my $value= shift;
46 30 my $default = shift;
47  
48 30 my $width = $default->{width};
49 30 my $height = $default->{height};
50  
51 30 ▶ if ($value =~ m/(\d+),(\d+)/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($value =~ /(\d+),(\d+)/) { } 7 23 30
elsif ($value =~ /,(\d+)/) { } 3 20 23
elsif ($value =~ /(\d+)/) { } 5 15 20
52 7 ($width , $height ) = $value =~ m/(\d+),(\d+)/;
53 }
54 elsif($value =~ m/,(\d+)/ ) {
55 3 ( $height ) = $value =~ m/,(\d+)/;
56 }
57 elsif($value =~ m/(\d+)/ ) {
58 5 ( $width ) = $value =~ m/(\d+)/;
59 }
60  
61 30 return ( $width , $height );
62 }
63 14 1;
64  
65 =head1 NAME
66  
67 Text::Livedoor::Wiki::Utils - utilities
68  
69 =head1 DESCRIPTION
70  
71 utilities
72  
73 =head1 FUNCTION
74  
75 =head2 escape
76  
77 escape HTML
78  
79 =head2 escape_more
80  
81 escape more HTML
82  
83 =head2 get_width_height
84  
85 getting width and height
86  
87 =head2 is_image_url
88  
89 check its image URL or not
90  
91 =head2 is_url
92  
93 check its URL or not
94  
95 =head2 sanitize_uri
96  
97 sanitize URL
98  
99 =head1 AUTHOR
100  
101 polocky
102  
103 =cut
« Wiki/Plugin/Inline/WikiPage.pm ↑ Summary Wiki/Plugin.pm »