The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Class::StorageFactory::YAML - object factory to fetch and store objects via YAML

SYNOPSIS

    use Class::StorageFactory::YAML;

        my $astronauts = Class::StorageFactory::YAML->new(
                storage => 'astronaut_data',
                type    => 'Astronaut',
        );

        my $flyboy  = eval { $astronauts->fetch( 'Yeager' ) };
        warn "No Chuck found\n" if $@;

DESCRIPTION

Class::StorageFactory::YAML is an object factory to fetch and store object data to and from YAML files.

METHODS

new( storage => $storage, type => $type )

Creates a new object of this class. This takes two required parameters, storage and type. storage is the name of the directory holding the .yml files associated with this factory. type is the name of the class to use when creating objects. If you store data for the Astronaut module in the astronaut_data directory, create a factory with:

        my $space_camp = Class::StorageFactory::YAML->new( 
                storage => 'astronaut_data',
                type    => 'Astronaut',
        );

This method will throw an exception unless you have provided both attributes.

storage()

Accessor for the storage attribute set in the constructor. You cannot set this from here; you can only read it.

type()

Accessor for the type attribute set in the constructor. You cannot set this from here; you can only read it.

fetch( $id )

Given an astronaut's $id, attempts to fetch the object from storage. If the object does not appear to exist based on $id, this will throw an exception. If it does exist, it will pass the data retrieved from storage to the constructor for the class identified by the type attribute (set in the constructor).

In the example above, fetch() looks for data for Yeager in astronaut_data/Yeager.yml.

store( $id, $object )

Calls the data() method on the received $object to retrieve the storable data and stores it in the storage location, identified by the $id.

If you want to clone an astronaut in $flyboy, you can do so with:

        $space_camp->store( 'ChuckClone', $flyboy );

AUTHOR

chromatic, <chromatic at wgz dot org>

BUGS

No known bugs.

COPYRIGHT

Copyright (c) 2005, chromatic. Some rights reserved.

This module is free software; you can use, redistribute, and modify it under the same terms as Perl 5.8.