| 1 | package Template::Plugin::Filter::Base64; | ||||||||||
| 2 | 2 | ▶ | use 5.008001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use Template::Plugin::Filter; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use base qw( Template::Plugin::Filter ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 2 | ▶ | use Encode; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use MIME::Base64 qw(encode_base64); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use HTML::Entities qw(encode_entities_numeric); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 2 | our $VERSION = "0.07"; | |||||||||
| 14 | |||||||||||
| 15 | 7 | ▶ | sub init { | ||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 16 | 7 | my ($self) = @_; | |||||||||
| 17 | 7 | $self->{_DYNAMIC} = 1; | |||||||||
| 18 | 7 | $self->install_filter('b64'); | |||||||||
| 19 | 7 | return $self; | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | 7 | ▶ | sub filter { | ||||||||
|
Subroutine
filter: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||
| 23 | 7 | my ($self, $text, $args, $conf) = @_; | |||||||||
| 24 | |||||||||||
| 25 | 7 | $conf = $self->merge_config($conf); | |||||||||
| 26 | |||||||||||
| 27 | 7 | ▶ | if ($conf->{trim}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 6 | $text =~ s/^\s+//ms; | |||||||||
| 29 | 6 | $text =~ s/\s+$//ms; | |||||||||
| 30 | } | ||||||||||
| 31 | 7 | ▶ | if($conf->{safeurl}){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 1 | return MIME::Base64::encode_base64url($text); | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 6 | my @encode_args = (); | |||||||||
| 36 | |||||||||||
| 37 | |||||||||||
| 38 | 6 | ▶ | if ($conf->{use_html_entity}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 1 | my $charset = $conf->{use_html_entity}; | |||||||||
| 40 | 1 | ▶ | if($charset){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 1 | $text = decode($charset, $text) | |||||||||
| 42 | } | ||||||||||
| 43 | 1 | $text = Encode::encode('UTF-8',$text); | |||||||||
| 44 | 1 | Encode::_utf8_on($text); | |||||||||
| 45 | |||||||||||
| 46 | 1 | $text = encode_entities_numeric($text); | |||||||||
| 47 | |||||||||||
| 48 | }else{ | ||||||||||
| 49 | 5 | ▶ | utf8::encode($text) if utf8::is_utf8($text); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | } | ||||||||||
| 51 | 6 | ▶ | if ($conf->{dont_broken_into_lines_each_76_char}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 4 | push @encode_args, ''; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 6 | unshift @encode_args, $text; | |||||||||
| 56 | |||||||||||
| 57 | 6 | my $encoded = &encode_base64(@encode_args); | |||||||||
| 58 | |||||||||||
| 59 | 6 | return $encoded | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 2 | 1; | |||||||||
| 63 | __END__ | ||||||||||