NAME
ClearPress::model - a base class for the data-model of the ClearPress MVC family
VERSION
$LastChangedRevision: 12 $
SYNOPSIS
use strict;
use warning;
use base qw(ClearPress::model);
__PACKAGE__->mk_accessors(__PACKAGE__->fields());
sub fields { return qw(...); }
DESCRIPTION
SUBROUTINES/METHODS
fields
my @aFields = $oModel->fields();
my @aFields = __PACKAGE__->fields();
primary_key - usually the first element of fields();
my $sPrimaryKey = $oModel->fields();
table - database table name this class represents
my $sTableName = $oModel->table();
init - post-constructor hook, called by new();
new - Constructor
my $oInstance = ClearPress::model::subclass->new();
util - ClearPress::util object
my $oUtil = ClearPress::model::subclass->util();
my $oUtil = $oInstance->util();
get - generic 'get' accessor, derived from Class::Accessor.
Invokes $self->read() if necessary.
my $sFieldValue = $oModel->get($sFieldName);
gen_getarray - Arrayref of objects of a given type for a given database query
my $arObjects = $oModel->gen_getarray('ClearPress::model::subclass',
q(SELECT a,b,c FROM x,y WHERE x.d=? AND y.e=?),
@bind_params);
gen_getall - Arrayref of all objects of type (ref $self) or a given class
my $arObjects = $oModel->gen_getall();
my $arObjects = $oModel->gen_getall('ClearPress::otherclass');
gen_getobj - An object of a given class based on the value of the primary key in that class equalling the value in the same field-name in this object.
my $oObj = $self->gen_getobj($sClass);
gen_getfriends - arrayref of relatives related by this model's primary key
my $arObjects = $oModel->gen_getfriends($sClass);
my $arObjects = $oModel->gen_getfriends($sClass, $sCacheKey);
gen_getfriends_through - arrayref of relatives related by this model's primary key through an additional join table
my $arObjects = $oModel->gen_getfriends($sClass, $sJoinTable);
my $arObjects = $oModel->gen_getfriends($sClass, $sJoinTable, $sCacheKey);
gen_getobj_through - fetch a relative through a join table
my $oRelative = $oModel->gen_getobj_through($sClass, $sJoinTable);
my $oRelative = $oModel->gen_getobj_through($sClass, $sJoinTable, $sCacheKey);
hasa - one:one package relationship
__PACKAGE__->hasa('my::pkg');
__PACKAGE__->hasa(['my::pkg1', 'my::pkg2']);
__PACKAGE__->hasa({method => 'my::fieldpkg'});
__PACKAGE__->hasa([{method_one => 'my::pkg1'},
{method_two => 'my::pkg2'});
hasmany - one:many package relationship
__PACKAGE__->hasmany('my::pkg');
If my::pkg has a table of "package" then this creates a method "sub
packages" in $self, yielding an arrayref of my::pkg objects related
by the primary_key of $self.
__PACKAGE__->hasmany(['my::pkg1', 'my::pkg2']);
Define multiple relationships together.
__PACKAGE__->hasmany({method => 'my::fieldpkg'});
Defines a method "sub methods" in $self yielding an arrayref of
my::fieldpkg objects related by the primary_key of $self.
__PACKAGE__->hasmany([{method_one => 'my::pkg1'},
{method_two => 'my::pkg2'});
Defines multiple relationships with overridden method names.
has_a - synonym for hasa()
belongs_to - synonym for hasa()
has_many - synonym for hasmany()
has_many_through - arrayref of related entities through a join table
Define a 'users' method in this class which fetches users like so:
SELECT u.id_user, u.foo, u.bar
FROM user f, centre_user t
WHERE t.id_this = ? # the primary_key for $self's class
AND t.id_user = f.id_user # the primary_key for friend 'user'
__PACKAGE__->has_many_through(['user|centre_user']);
belongs_to_through - a one-to-one relationship, like belongs_to, but through a join table
__PACKAGE__->belongs_to_through(['user|friend', 'user|enemy']);
create - Generic INSERT into database
$oModel->create();
read - Generic lazy-load from the database
$oModel->load();
update - Generic UPDATE into database against primary_key
$oModel->update();
delete - Generic delete from database
$oModel->delete();
save - Generic save object to database
$oModel->save();
zdate - Generic Zulu-date based on object's date() method or gmtime
my $sZuluTime = $oModel->zdate();
as_json - JSON representation of this object
my $sJSON = $oModel->as_json();
as_xml - XML representation of this object
my $oXML = $oModel->as_xml();
DIAGNOSTICS
CONFIGURATION AND ENVIRONMENT
DEPENDENCIES
Class::Accessor ClearPress::util English Carp
INCOMPATIBILITIES
BUGS AND LIMITATIONS
AUTHOR
Roger Pettett, <rpettett@cpan.org>
LICENSE AND COPYRIGHT
Copyright (C) 2007 Roger Pettett
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.