NAME

CatalystX::CRUD::Object - an instance returned from a CatalystX::CRUD::Model

SYNOPSIS

package My::Object;
use base qw( CatalystX::CRUD::Object );

sub create { shift->delegate->save }
sub read   { shift->delegate->load }
sub update { shift->delegate->save }
sub delete { shift->delegate->remove }

1;

DESCRIPTION

A CatalystX::CRUD::Model returns instances of CatalystX::CRUD::Object.

The assumption is that the Object knows how to manipulate the data it represents, typically by holding an instance of an ORM or other data model in the delegate accessor, and calling methods on that instance.

So, for example, a CatalystX::CRUD::Object::RDBO has a Rose::DB::Object instance, and calls its RDBO object's methods.

The idea is to provide a common CRUD API for various backend storage systems.

METHODS

The following methods are provided.

new

Generic constructor. args may be a hash or hashref.

delegate

The delegate() accessor is a holder for the object instance that the CXCO instance has. A CXCO object "hasa" instance of another class in its delegate() slot. The delegate is the thing that does the actual work; the CXCO object just provides a container for the delegate to inhabit.

Think of delegate as a noun, not a verb, as in "The United Nations delegate often slept here."

REQUIRED METHODS

A CXCO subclass needs to implement at least the following methods:

create

Write a new object to store.

read

Load a new object from store.

update

Write an existing object to store.

delete

Remove an existing object from store.

is_new

Return results should be boolean indicating whether the object already exists or not. Expectation is code like:

if ($object->is_new) {
    $object->create;
}
else {
    $object->update;
}

serialize

Stringify the object. This class overloads the string operators to call this method.

Your delegate class should implement a serialize() method or stringify to something useful.

AUTOLOAD

Some black magic hackery to make Object classes act like they are overloaded delegate()s.

can( method )

Overrides basic can() method to call can() first on the delegate and secondly (fallback) on the Object class itself.

AUTHOR

Peter Karman, <perl at peknet.com>

BUGS

Please report any bugs or feature requests to bug-catalystx-crud at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CatalystX-CRUD. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc CatalystX::CRUD

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2007 Peter Karman, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.