line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
App::Basis::ConvertText2::Support |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 DESCRIPTION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Support functions for L and its plugins |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------- |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
package App::Basis::ConvertText2::Support; |
16
|
|
|
|
|
|
|
$App::Basis::ConvertText2::Support::VERSION = '0.4'; |
17
|
1
|
|
|
1
|
|
12
|
use 5.10.0; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
48
|
|
18
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
19
|
1
|
|
|
1
|
|
13
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
20
|
1
|
|
|
1
|
|
6
|
use Path::Tiny ; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
66
|
|
21
|
1
|
|
|
1
|
|
5
|
use Digest::MD5 qw(md5_hex); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
22
|
1
|
|
|
1
|
|
1035
|
use Encode qw(encode_utf8); |
|
1
|
|
|
|
|
13442
|
|
|
1
|
|
|
|
|
113
|
|
23
|
1
|
|
|
1
|
|
661
|
use GD; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use Exporter; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use vars qw( @EXPORT @ISA); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# this is the list of things that will get imported into the loading packages |
31
|
|
|
|
|
|
|
# namespace |
32
|
|
|
|
|
|
|
@EXPORT = qw( |
33
|
|
|
|
|
|
|
cachefile |
34
|
|
|
|
|
|
|
create_sig |
35
|
|
|
|
|
|
|
create_img_src |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------- |
39
|
|
|
|
|
|
|
# check if a file is in the cache, if so return the full file name |
40
|
|
|
|
|
|
|
sub cachefile { |
41
|
|
|
|
|
|
|
my ($cache, $filename) = @_; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# make sure we are working in the right dir |
44
|
|
|
|
|
|
|
return $cache . "/" . path($filename)->basename; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------- |
49
|
|
|
|
|
|
|
# create a signature based on content and params to a element |
50
|
|
|
|
|
|
|
sub create_sig { |
51
|
|
|
|
|
|
|
my ( $content, $params ) = @_; |
52
|
|
|
|
|
|
|
my $param_str = join( ' ', map { "$_='$params->{$_}'"; } sort keys %$params ); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
return md5_hex( $content . encode_utf8($param_str) ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------- |
58
|
|
|
|
|
|
|
# create a HTML img element using the passed in filename, also grab the |
59
|
|
|
|
|
|
|
# image from the file and add its width and height to the attributes |
60
|
|
|
|
|
|
|
sub create_img_src { |
61
|
|
|
|
|
|
|
my ( $file, $alt ) = @_; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
return "" if ( !$file || !-f $file ); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $out = "
|
66
|
|
|
|
|
|
|
$out .= "alt='$alt' " if ($alt); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $image = GD::Image->new($file); |
69
|
|
|
|
|
|
|
if ($image) { |
70
|
|
|
|
|
|
|
$out .= "height='" . $image->height() . "' width='" . $image->width() . "' "; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$out .= "/>"; |
74
|
|
|
|
|
|
|
return $out; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------- |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |