| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Template::Plugin::Filter::Base64; | 
| 2 | 2 |  |  | 2 |  | 56118 | use 5.008001; | 
|  | 2 |  |  |  |  | 12 |  | 
| 3 | 2 |  |  | 2 |  | 9 | use strict; | 
|  | 2 |  |  |  |  | 10 |  | 
|  | 2 |  |  |  |  | 45 |  | 
| 4 | 2 |  |  | 2 |  | 7 | use warnings; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 49 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 2 |  |  | 2 |  | 778 | use Template::Plugin::Filter; | 
|  | 2 |  |  |  |  | 9661 |  | 
|  | 2 |  |  |  |  | 53 |  | 
| 7 | 2 |  |  | 2 |  | 13 | use base qw( Template::Plugin::Filter ); | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 109 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 2 |  |  | 2 |  | 888 | use Encode; | 
|  | 2 |  |  |  |  | 16423 |  | 
|  | 2 |  |  |  |  | 138 |  | 
| 10 | 2 |  |  | 2 |  | 729 | use MIME::Base64 qw(encode_base64); | 
|  | 2 |  |  |  |  | 941 |  | 
|  | 2 |  |  |  |  | 113 |  | 
| 11 | 2 |  |  | 2 |  | 780 | use HTML::Entities qw(encode_entities_numeric); | 
|  | 2 |  |  |  |  | 9260 |  | 
|  | 2 |  |  |  |  | 541 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | our $VERSION = "0.05"; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | sub init { | 
| 16 | 5 |  |  | 5 | 0 | 61530 | my ($self) = @_; | 
| 17 | 5 |  |  |  |  | 19 | $self->{_DYNAMIC} = 1; | 
| 18 | 5 |  |  |  |  | 20 | $self->install_filter('b64'); | 
| 19 | 5 |  |  |  |  | 221 | return $self; | 
| 20 |  |  |  |  |  |  | } | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | sub filter { | 
| 23 | 5 |  |  | 5 | 0 | 418 | my ($self, $text, $args, $conf) = @_; | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 5 |  |  |  |  | 18 | $conf = $self->merge_config($conf); | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 5 | 100 |  |  |  | 68 | if ($conf->{trim}) { | 
| 28 | 4 |  |  |  |  | 18 | $text =~ s/^\s+//ms; | 
| 29 | 4 |  |  |  |  | 20 | $text =~ s/\s+$//ms; | 
| 30 |  |  |  |  |  |  | } | 
| 31 | 5 | 100 |  |  |  | 15 | if($conf->{safeurl}){ | 
| 32 | 1 |  |  |  |  | 7 | return MIME::Base64::encode_base64url($text); | 
| 33 |  |  |  |  |  |  | } | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 4 |  |  |  |  | 9 | my @encode_args = (); | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 4 | 100 |  |  |  | 16 | if ($conf->{use_html_entity}) { | 
| 39 | 1 |  |  |  |  | 2 | my $charset = $conf->{use_html_entity}; | 
| 40 | 1 | 50 |  |  |  | 4 | if($charset){ | 
| 41 | 1 |  |  |  |  | 8 | $text = decode($charset, $text) | 
| 42 |  |  |  |  |  |  | } | 
| 43 | 1 |  |  |  |  | 2806 | $text = Encode::encode('UTF-8',$text); | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 1 |  |  |  |  | 247 | Encode::_utf8_on($text); | 
| 46 | 1 |  |  |  |  | 5 | $text = encode_entities_numeric($text); | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | } | 
| 49 | 4 | 100 |  |  |  | 87 | if ($conf->{dont_broken_into_lines_each_76_char}) { | 
| 50 | 2 |  |  |  |  | 5 | push @encode_args, ''; | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  |  | 
| 53 | 4 |  |  |  |  | 9 | unshift @encode_args, $text; | 
| 54 |  |  |  |  |  |  |  | 
| 55 | 4 |  |  |  |  | 26 | my $encoded = &encode_base64(@encode_args); | 
| 56 |  |  |  |  |  |  |  | 
| 57 | 4 |  |  |  |  | 25 | return $encoded | 
| 58 |  |  |  |  |  |  | } | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | 1; | 
| 61 |  |  |  |  |  |  | __END__ |