| 1 | #======================================================================== | ||
| 2 | # | ||
| 3 | # Badger::Codec | ||
| 4 | # | ||
| 5 | # DESCRIPTION | ||
| 6 | # Base class codec providing a generic API for encoding/decoding data. | ||
| 7 | # | ||
| 8 | # AUTHOR | ||
| 9 | # Andy Wardley <abw@wardley.org> | ||
| 10 | # | ||
| 11 | #======================================================================== | ||
| 12 | |||
| 13 | package Badger::Codec; | ||
| 14 | |||
| 15 | use Badger::Class | ||
| 16 | version => 0.01, | ||
| 17 | debug => 0, | ||
| 18 | base => 'Badger::Base', | ||
| 19 | utils => 'UTILS'; | ||
| 20 | |||
| 21 | sub encode { | ||
| 22 | shift->not_implemented; | ||
| 23 | } | ||
| 24 | |||
| 25 | sub decode { | ||
| 26 | shift->not_implemented; | ||
| 27 | } | ||
| 28 | |||
| 29 | |||
| 30 | # This is the "brute force and ignorance" approach to creating stand-alone | ||
| 31 | # subroutines. They get the job done, albeit at the overhead of an extra | ||
| 32 | # method call. Subclasses can do something better, like exporting existing | ||
| 33 | # subrefs directly. | ||
| 34 | |||
| 35 | sub encoder { | ||
| 36 | my $self = shift; | ||
| 37 | return sub { $self->encode(@_) }; | ||
| 38 | } | ||
| 39 | |||
| 40 | sub decoder { | ||
| 41 | my $self = shift; | ||
| 42 | return sub { $self->decode(@_) }; | ||
| 43 | } | ||
| 44 | |||
| 45 | 1; | ||
| 46 | |||
| 47 | |||
| 48 | __END__ |