NAME
DBIx::SearchBuilder::Record - Perl extension for subclassing, so you can deal with a Record
SYNOPSIS
module MyRecord;
use DBIx::SearchBuilder::Record;
@ISA = (DBIx::SearchBuilder::Record);
sub _Init {
my $self = shift;
my $DBIxHandle = shift; # A DBIx::SearchBuilder::Handle::foo object for your database
$self->_Handle($DBIxHandle);
$self->Table("Users");
return($self->SUPER::_Init(@_));
}
#Preferred and most efficient way to specify fields attributes in a derived
#class, used by the autoloader to construct Attrib and SetAttrib methods.
# read: calling $Object->Foo will return the value of this record's Foo column # write: calling $Object->SetFoo with a single value will set Foo's value in
# both the loaded object and the database
sub _ClassAccessible {
{
Tofu => { 'read'=>1, 'write'=>1 },
Maz => { 'auto'=>1, },
Roo => { 'read'=>1, 'auto'=>1, 'public'=>1, },
};
}
# specifying an _Accessible subroutine in a derived class is depriciated.
# only '/' and ',' delimiters work, not full regexes
sub _Accessible {
my $self = shift;
my %Cols = (
id => 'read', # id is an immutable primary key
Username => 'read/write', #read/write.
Password => 'write', # password. write only. see sub IsPassword
Created => 'read' # A created date. read-only
);
return $self->SUPER::_Accessible(@_, %Cols);
}
# A subroutine to check a user's password without ever returning the current password
#For security purposes, we didn't expose the Password method above
sub IsPassword {
my $self = shift;
my $try = shift;
# note two __s in __Value. Subclasses may muck with _Value, but they should
# never touch __Value
if ($try eq $self->__Value('Password')) {
return (1);
}
else {
return (undef);
}
}
# Override DBIx::SearchBuilder::Create to do some checking on create
sub Create {
my $self = shift;
my %fields = ( UserId => undef,
Password => 'default', #Set a default password
@_);
#Make sure a userid is specified
unless ($fields{'UserId'}) {
die "No userid specified.";
}
#Get DBIx::SearchBuilder::Record->Create to do the real work
return ($self->SUPER::Create( UserId => $fields{'UserId'},
Password => $fields{'Password'},
Created => time ));
}
DESCRIPTION DBIx::SearchBuilder::Record is designed to work with DBIx::SearchBuilder.
METHODS
id
Returns this row's primary key.
_AccessibleLoad COLUMN => OPERATIONS, ...
_ClassAccessible HASHREF
Preferred and most efficient way to specify fields attributes in a derived class.
sub _ClassAccessible {
{
Tofu => { 'read'=>1, 'write'=>1 },
Maz => { 'auto'=>1, },
Roo => { 'read'=>1, 'auto'=>1, 'public'=>1, },
};
}
__Value
Takes a field name and returns that field's value. Subclasses should never overrid __Value.
_Value
_Value takes a single column name and returns that column's value for this row. Subclasses can override _Value to insert custom access control.
_Set
_Set takes a single column name and a single unquoted value. It updates both the in-memory value of this column and the in-database copy. Subclasses can override _Set to insert custom access control.
Load
Takes a single argument, $id. Calls LoadByRow to retrieve the row whose primary key is $id
LoadByCol
Takes two arguments, a column and a value. The column can be any table column which contains unique values. Behavior when using a non-unique value is undefined
LoadByCols
Takes a hash of columns and values. Loads the first record that matches all keys.
LoadById
Loads a record by its primary key. TODO: BUG: Column name is currently hard coded to 'id'
LoadFromHash
Takes a hashref, such as created by DBIx::SearchBuilder and populates this record's
loaded values hash.
Create
Takes an array of key-value pairs and drops any keys that aren't known as columns for this recordtype
Table
Returns or sets the name of the current Table
_Handle
Returns or sets the current DBIx::SearchBuilder::Handle object
Private: _DownCaseValuesHash
Takes no parameters and returns no arguments. This private routine iterates through $self->{'values'} and makes sure that all keys are lowercase.
AUTHOR
Jesse Vincent, <jesse@fsck.com> Ivan Kohler, <ivan-rt@420.am>
SEE ALSO
perl(1).