Badger::Codec::YAML - encode/decode data using YAML


Badger documentation Contained in the Badger distribution.

Index


Code Index:

NAME

Top

Badger::Codec::YAML - encode/decode data using YAML

SYNOPSIS

Top

    use Badger::Codec::YAML;
    my $codec   = Badger::Codec::YAML->new();
    my $encoded = $codec->encode("Hello World");
    my $decoded = $codec->decode($encoded);

DESCRIPTION

Top

This module implements a subclass of Badger::Codec which uses the YAML module to encode and decode data to and from YAML.

METHODS

Top

encode($data)

Encodes $data to YAML.

    $encoded = Badger::Codec::YAML->encode($data);   

decode($data)

Decodes $data from YAML.

    $decoded = Badger::Codec::YAML->decode($encoded);

encoder()

This method returns a reference to the real subroutine that's doing all the encoding work, i.e. the Dump() subroutine in YAML.

decoder()

This method returns a reference to the real subroutine that's doing all the decoding work, i.e. the Load() subroutine in YAML.

AUTHOR

Top

Andy Wardley http://wardley.org/

COPYRIGHT

Top

SEE ALSO

Top

Badger::Codecs, Badger::Codec, YAML


Badger documentation Contained in the Badger distribution.

#========================================================================
#
# Badger::Codec::YAML
#
# DESCRIPTION
#   Codec module for encoding/decoding YAML
#
# AUTHOR
#   Andy Wardley   <abw@wardley.org>
#
#========================================================================

package Badger::Codec::YAML;

use Badger::Class
    version => 0.01,
    base    => 'Badger::Codec',
    import  => 'class CLASS';

BEGIN {
    eval { require 'YAML.pm' } 
        || CLASS->error("You don't have YAML installed");
}

sub encode {
    my $self = shift;
    YAML::Dump(shift);
}

sub decode {
    my $self = shift;
    YAML::Load(shift);
}

# shortcuts straight to the real encoder/decoder subs for efficient aliasing

sub encoder {
    \&YAML::Dump;
}

sub decoder {
    \&YAML::Load;
}


1;


__END__

# Local Variables:
# mode: Perl
# perl-indent-level: 4
# indent-tabs-mode: nil
# End:
#
# vim: expandtab shiftwidth=4: