CatalystX::CRUD::ModelAdapter - make CRUD Controllers work with non-CRUD models


CatalystX-CRUD documentation Contained in the CatalystX-CRUD distribution.

Index


Code Index:

NAME

Top

CatalystX::CRUD::ModelAdapter - make CRUD Controllers work with non-CRUD models

SYNOPSIS

Top

 package My::ModelAdapter::Foo;
 use base qw( CatalystX::CRUD::ModelAdapter );

 # must implement the following methods
 sub new_object { }
 sub fetch      { }
 sub search     { }
 sub iterator   { }
 sub count      { }
 sub make_query { }
 sub search_related     { }
 sub iterator_related   { }
 sub count_related      { }

 1;

 # then in your CX::CRUD::Controller subclass
 package MyApp::Controller::CRUD;
 use base qw( CatalystX::CRUD::Controller );

 __PACKAGE__->config(
    'model_adapter' => 'My::ModelAdapter::Foo'
 );

 1;

DESCRIPTION

Top

CatalystX::CRUD::ModelAdapter allows you to use existing, non-CRUD Models with the CatalystX::CRUD::Controller API. The ModelAdapter class implements a similar API to the CX::CRUD::Model, but does not inherit from Catalyst::Model and should not sit in the ::Model namespace.

If a 'model_adapter' config value is present in a CX::CRUD::Controller subclass, the ModelAdapter instance will be called instead of the 'model_name' instance. The model_name accessor is available on the ModelAdapter instance and is set automatically at instantiation time by the calling Controller.

This documentation is intended for ModelAdapter developers.

CONFIGURATION

Top

You may configure your CXCM-derived Models in the usual way (see the Catalyst Manual).

METHODS

Top

CatalystX::CRUD::ModelAdapter inherits from CatalystX::CRUD.

The following methods should be implemented in your subclass.

new_object( controller, context )

Should return a new instance from the Model you are adapting.

fetch( controller, context, args )

Should return an instance of the Model you are adapting, based on args.

search( controller, context, args )

Should return an arrayref of instances of the Model you are adapting, based on args.

iterator( controller, context, args )

Should return an iterator of instances of the Model you are adapting, based on args.

count( controller, context, args )

Should return an integer representing the numbef of matching instances of the Model you are adapting, based on args.

make_query( controller, context )

Should return appropriate values for passing to search(), iterator() and count(). See CataystX::CRUD::Model for examples.

has_relationship( controller, context, obj, rel_name )

Should return true or false as to whether rel_name exists for obj.

It is up to the subclass to implement this method.

CRUD Methods

Top

The following methods are implemented in CatalystX::CRUD::Object when using the CatalystX::CRUD::Model API. When using the ModelAdapter API, they should be implemented in the adapter class.

create( context, object )

Should implement the C in CRUD.

read( context, object )

Should implement the R in CRUD.

update( context, object )

Should implement the U in CRUD.

delete( context, object )

Should implement the D in CRUD.

AUTHOR

Top

Peter Karman, <perl at peknet.com>

BUGS

Top

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

Top

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

    perldoc CatalystX::CRUD

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/CatalystX-CRUD

* CPAN Ratings

http://cpanratings.perl.org/d/CatalystX-CRUD

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=CatalystX-CRUD

* Search CPAN

http://search.cpan.org/dist/CatalystX-CRUD

COPYRIGHT & LICENSE

Top


CatalystX-CRUD documentation Contained in the CatalystX-CRUD distribution.
package CatalystX::CRUD::ModelAdapter;
use strict;
use warnings;
use base qw(
    CatalystX::CRUD
    Class::Accessor::Fast
);
use MRO::Compat;
use mro 'c3';
use Carp;

__PACKAGE__->mk_accessors(qw( model_name model_meta context app_class ));

sub new_object { shift->throw_error("must implement new_object"); }

sub fetch { shift->throw_error("must implement fetch") }

sub search { shift->throw_error("must implement search") }

sub iterator { shift->throw_error("must implement iterator") }

sub count { shift->throw_error("must implement count") }

sub make_query { shift->throw_error("must implement make_query()") }

sub search_related   { shift->throw_error("must implement search_related") }
sub iterator_related { shift->throw_error("must implement iterator_related") }
sub count_related    { shift->throw_error("must implement count_related") }

sub add_related { shift->throw_error("must implement add_related()") }
sub rm_related  { shift->throw_error("must implement rm_related()") }

sub has_relationship {
    shift->throw_error("must implement has_relationship()");
}

sub create { shift->throw_error("must implement create()") }

sub read { shift->throw_error("must implement read()") }

sub update { shift->throw_error("must implement update()") }

sub delete { shift->throw_error("must implement delete()") }

1;

__END__