Badger::Codec::Encoding - base class codec for different encodings


Badger documentation  | view source Contained in the Badger distribution.

Index


NAME

Top

Badger::Codec::Encoding - base class codec for different encodings

SYNOPSIS

Top

    package My::Encoding::utf8;
    use base 'Badger::Codec::Encoding';
    use constant encoding => 'utf8';

    package main;
    my $codec = My::Encoding::utf8->new;
    my $encoded = $codec->encode("...some utf8 data...");
    my $decoded = $codec->decode($encoded);

DESCRIPTION

Top

This module is a subclass of Badger::Codec which itself acts as a base class for various specific encoding modules.

METHODS

Top

encoding()

This constant method returns the encoding for the codec. Subclasses are expected to redefine this method to return a string representing their specific encoding.

encode($data)

Method for encoding data. It uses the encoding() method to determine the encoding type and then calls the Encode encode() subroutine to do all the hard work.

    $encoded = $codec->encode($uncoded);

decode($data)

Method for decoding data. It uses the encoding() method to determine the encoding type and then calls the Encode decode() subroutine to do all the hard work.

    $decoded = $codec->decode($encoded);

encoder()

This method returns a subroutine reference which can be called to encode data.

    my $encoder = $codec->encode;
    $encoded = $encoder->($data);

decoder()

This method returns a suboroutine reference which can be called to decode data.

    my $decoder = $codec->decode;
    $decoded = $decoder->($data);

AUTHOR

Top

Andy Wardley http://wardley.org/

COPYRIGHT

Top

SEE ALSO

Top

Encode, Badger::Codec::Encode, Badger::Codec::Unicode, Badger::Codecs, Badger::Codec,


Badger documentation  | view source Contained in the Badger distribution.