File Coverage

blib/lib/Email/MIME/Kit/Role/KitReader.pm
Criterion Covered Total %
statement 13 13 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod 0 1 0.0
total 17 18 94.4


line stmt bran cond sub pod time code
1             package Email::MIME::Kit::Role::KitReader 3.000007;
2             # ABSTRACT: things that can read kit contents
3              
4 6     6   3827 use v5.20.0;
  6         32  
5 6     6   35 use Moose::Role;
  6         14  
  6         45  
6             with 'Email::MIME::Kit::Role::Component';
7              
8             #pod =head1 IMPLEMENTING
9             #pod
10             #pod This role also performs L<Email::MIME::Kit::Role::Component>.
11             #pod
12             #pod Classes implementing this role must provide a C<get_kit_entry> method. It will
13             #pod be called with one parameter, the name of a path to an entry in the kit. It
14             #pod should return a reference to a scalar holding the contents (as octets) of the
15             #pod named entry. If no entry is found, it should raise an exception.
16             #pod
17             #pod A method called C<get_decoded_kit_entry> is provided. It behaves like
18             #pod C<get_kit_entry>, but assumes that the entry for that name is stored in UTF-8
19             #pod and will decode it to text before returning.
20             #pod
21             #pod =cut
22              
23             requires 'get_kit_entry';
24              
25             sub get_decoded_kit_entry {
26 6     6 0 104 my ($self, $name) = @_;
27 6         29 my $content_ref = $self->get_kit_entry($name);
28              
29 6         90 require Encode;
30 6         39 my $decoded = Encode::decode('utf-8', $$content_ref);
31 6         685 return \$decoded;
32             }
33              
34 6     6   20781 no Moose::Role;
  6         16  
  6         34  
35             1;
36              
37             __END__
38              
39             =pod
40              
41             =encoding UTF-8
42              
43             =head1 NAME
44              
45             Email::MIME::Kit::Role::KitReader - things that can read kit contents
46              
47             =head1 VERSION
48              
49             version 3.000007
50              
51             =head1 PERL VERSION
52              
53             This library should run on perls released even a long time ago. It should work
54             on any version of perl released in the last five years.
55              
56             Although it may work on older versions of perl, no guarantee is made that the
57             minimum required version will not be increased. The version may be increased
58             for any reason, and there is no promise that patches will be accepted to lower
59             the minimum required perl.
60              
61             =head1 IMPLEMENTING
62              
63             This role also performs L<Email::MIME::Kit::Role::Component>.
64              
65             Classes implementing this role must provide a C<get_kit_entry> method. It will
66             be called with one parameter, the name of a path to an entry in the kit. It
67             should return a reference to a scalar holding the contents (as octets) of the
68             named entry. If no entry is found, it should raise an exception.
69              
70             A method called C<get_decoded_kit_entry> is provided. It behaves like
71             C<get_kit_entry>, but assumes that the entry for that name is stored in UTF-8
72             and will decode it to text before returning.
73              
74             =head1 AUTHOR
75              
76             Ricardo Signes <rjbs@cpan.org>
77              
78             =head1 COPYRIGHT AND LICENSE
79              
80             This software is copyright (c) 2023 by Ricardo Signes.
81              
82             This is free software; you can redistribute it and/or modify it under
83             the same terms as the Perl 5 programming language system itself.
84              
85             =cut