File Coverage

lib/Badger/Codec/Encode.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 4 4 100.0
total 26 26 100.0


line stmt bran cond sub pod time code
1             #========================================================================
2             #
3             # Badger::Codec::Encode
4             #
5             # DESCRIPTION
6             # A codec wrapper for Encode
7             #
8             # AUTHOR
9             # Andy Wardley
10             #
11             #========================================================================
12              
13             package Badger::Codec::Encode;
14              
15             use Badger::Class
16 2         17 version => 0.01,
17 2     2   2435 base => 'Badger::Codec';
  2         5  
18              
19 2     2   1099 use Encode qw();
  2         30316  
  2         60  
20 2     2   12 use bytes;
  2         7  
  2         9  
21              
22             sub encode {
23 5     5 1 26 my $self = shift;
24             # No, really, it's OK. This isn't one of those kind of GOTOs.
25             # This is an Offically OK version of GOTO which is really a special
26             # kind of subroutine call. See: perldoc -f goto
27 5         25 goto &Encode::encode;
28             }
29              
30             sub decode {
31 5     5 1 101 my $self = shift;
32             # we use goto rather than a call because a) it's quicker (the call
33             # stack frame is re-used) and b) because the prototypes for encode()
34             # and decode() would require us to shift all the arguments off the
35             # stack in order to pass them to encode()/decode() in an orderly
36             # fashion, e.g. my ($enc, $data) = @_; Encode::encode($enc, $data)
37             # rather than: Encode::encode(@_); # not allowed - prototype mismatch
38 5         27 goto &Encode::decode;
39             }
40              
41             sub encoder {
42 1     1 1 2 \&Encode::encode;
43             }
44              
45             sub decoder {
46 1     1 1 2 \&Encode::decode;
47             }
48              
49             1;
50              
51              
52             __END__