File Coverage

blib/lib/Encode/JP/Mobile/MIME.pm
Criterion Covered Total %
statement 30 33 90.9
branch 2 4 50.0
condition n/a
subroutine 8 10 80.0
pod 2 4 50.0
total 42 51 82.3


line stmt bran cond sub pod time code
1             package Encode::JP::Mobile::MIME;
2 24     24   164 use strict;
  24         53  
  24         1048  
3 24     24   127 use warnings;
  24         50  
  24         728  
4 24     24   127 use base 'Encode::Encoding';
  24         44  
  24         2294  
5              
6 24     24   136 use Encode ();
  24         48  
  24         505  
7 24     24   134 use Encode::JP::Mobile;
  24         83  
  24         1059  
8 24     24   41484 use MIME::Words;
  24         124978  
  24         8970  
9              
10             sub subject_encoding {
11 0     0 0 0 Encode::find_encoding('utf-8');
12             }
13              
14             sub charset_to_encoding {
15 0     0 0 0 my ($self, $charset) = @_;
16 0         0 Encode::find_encoding($charset);
17             }
18              
19             sub encode($$;$){
20 4     4 1 1585 my ($self, $str, $check) = @_;
21 4 50       21 my $encoding = $self->subject_encoding
22             or die "encoding is not found.";
23            
24 4         93 $str = $encoding->encode($str, $check);
25 4         107 $str = MIME::Words::encode_mimeword($str, 'B', $encoding->mime_name);
26 4         144 return $str;
27             }
28              
29             sub decode($$;$){
30 5     5 1 2881 my ($self, $str, $check) = @_;
31            
32 5         10 my $ret = "";
33 5         17 for my $part (MIME::Words::decode_mimewords($str)) {
34 5         191 my ($bytes, $charset) = @$part;
35 5 50       22 my $encoding = $self->charset_to_encoding($charset)
36             or die "encoding is not found for $charset.";
37            
38 5         98 $ret .= $encoding->decode($bytes, $check);
39             }
40            
41 5         74 return $ret;
42             }
43              
44             1;
45             __END__