line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Bubblegum Wrapper around Content Encoding |
2
|
|
|
|
|
|
|
package Bubblegum::Wrapper::Encoder; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
782
|
use 5.10.0; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
90
|
|
5
|
1
|
|
|
1
|
|
1322
|
use namespace::autoclean; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Bubblegum::Class; |
7
|
|
|
|
|
|
|
use Bubblegum::Exception; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Encode 'find_encoding'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
extends 'Bubblegum::Object::Instance'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.44'; # VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub BUILD { |
16
|
|
|
|
|
|
|
my $self = shift; |
17
|
|
|
|
|
|
|
$self->data->typeof('str') |
18
|
|
|
|
|
|
|
or Bubblegum::Exception->throw( |
19
|
|
|
|
|
|
|
verbose => 1, |
20
|
|
|
|
|
|
|
message => ref($self)->format( |
21
|
|
|
|
|
|
|
'Wrapper package "%s" requires string data' |
22
|
|
|
|
|
|
|
), |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub decode { |
27
|
|
|
|
|
|
|
my $self = shift; |
28
|
|
|
|
|
|
|
my $type = shift // 'utf-8'; |
29
|
|
|
|
|
|
|
my $decoder = find_encoding $type; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
return undef unless $decoder; |
32
|
|
|
|
|
|
|
return $decoder->decode($self->data); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub encode { |
36
|
|
|
|
|
|
|
my $self = shift; |
37
|
|
|
|
|
|
|
my $type = shift // 'utf-8'; |
38
|
|
|
|
|
|
|
my $encoder = find_encoding $type; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
return undef unless $encoder; |
41
|
|
|
|
|
|
|
return $encoder->encode($self->data); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |