File Coverage

blib/lib/Template/Plugin/GoogleLaTeX.pm
Criterion Covered Total %
statement 39 44 88.6
branch 5 10 50.0
condition 1 2 50.0
subroutine 9 9 100.0
pod 2 2 100.0
total 56 67 83.5


line stmt bran cond sub pod time code
1             package Template::Plugin::GoogleLaTeX;
2            
3 2     2   359764 use strict; use warnings;
  2     2   5  
  2         78  
  2         11  
  2         4  
  2         110  
4             our $VERSION = '0.03';
5            
6 2     2   2124 use Template::Plugin::Filter;
  2         11079  
  2         74  
7 2     2   19 use base qw( Template::Plugin::Filter );
  2         4  
  2         157  
8            
9 2     2   2073 use URI::Escape;
  2         3483  
  2         186  
10 2     2   18 use constant API_URL => 'http://chart.apis.google.com/chart?cht=tx';
  2         4  
  2         185  
11            
12 2         971 use constant IMG_ATTRS => [ qw(
13             src id name class style alt title longdesc align width height border
14             hspace vspace usemap ismap lang dir onclick ondblclick onmousedown
15             onmouseup onmouseover onmousemove onmouseout onkeypress onkeydown
16             onkeyup
17 2     2   13 ) ];
  2         3  
18            
19             sub init {
20 2     2 1 5171 my $self = shift;
21 2         23 $self->{ _DYNAMIC} = 1;
22            
23             # first arg can specify filter name
24 2   50     28 $self->install_filter($self->{ _ARGS }->[0] || 'latex');
25            
26 2         99 return $self;
27             }
28            
29             sub filter {
30 2     2 1 197 my ($self, $text, $args, $config) = @_;
31            
32 2         5 my %config = %{ $self->merge_config($config) };
  2         12  
33 2         22 my %qs;
34            
35 2         7 $qs{chl} = uri_escape( $text );
36            
37 2 50       73 if ( defined (my $h = $config{height} ) ) {
38 0 0       0 if ( defined ( my $w = $config{width} ) ) {
39 0         0 $qs{chs} ="${h}x${w}"
40             }
41             else {
42 0         0 $qs{chs} = $h;
43             }
44             }
45            
46 2 50       10 if ( defined ( my $fill = $config{fill} ) ) {
47 0         0 $qs{chf} = $fill;
48             }
49            
50 2 50       7 if ( defined ( my $color = $config{color} ) ) {
51 0         0 $qs{chco} = $color;
52             }
53            
54 2         26 $config{src} = join('&',
55             $self->API_URL,
56             (
57             map sprintf(q{%s=%s}, $_, $qs{$_}), keys %qs
58             ),
59             );
60            
61 2         4 my @attrs = grep defined( $config{$_} ), @{ $self->IMG_ATTRS };
  2         28  
62            
63 2         12 my $out = join(' ',
64             '
65             (
66             map sprintf(q{%s="%s"}, $_, $config{$_}), @attrs
67             ),
68             );
69 2 100       10 $out .= $config{xhtml} ? '/>' : '>';
70 2         20 return $out;
71            
72             }
73            
74             "Template::Plugin::GoogleLaTeX"
75             __END__