HTML::Tested::ClassDBI - Enhances HTML::Tested to work with Class::DBI
package MyClass; use base 'HTML::Tested::ClassDBI'; __PACKAGE__->ht_add_widget('HTML::Tested::Value' , id => cdbi_bind => "Primary"); __PACKAGE__->ht_add_widget('HTML::Tested::Value' , x => cdbi_bind => ""); __PACKAGE__->ht_add_widget('HTML::Tested::Value::Upload' , x => cdbi_upload => "largeobjectoid"); __PACKAGE__->bind_to_class_dbi('MyClassDBI'); # And later somewhere ... # Query and load underlying Class::DBI: my $list = MyClass->query_class_dbi(search => x => 15); # or sync it to the database: $obj->cdbi_create_or_update;
This class provides mapping between Class::DBI and HTML::Tested objects.
It inherits from HTML::Tested. Widgets created with ht_add_widget can have additional cdbi_bind property.
ht_add_widget
cdbi_bind
After calling bind_to_class_dbi you would be able to automatically synchronize between HTML::Tested::ClassDBI instance and underlying Class::DBI.
bind_to_class_dbi
Binds $class to $cdbi_class, by going over all fields declared with cdbi_bind or cdbi_upload option.
cdbi_upload
cdbi_bind option value could be one of the following: name of the column, empty string for the column named the same as field or for array of columns.
cdbi_upload can be used to upload file into the database. Uploaded file is stored as PostgreSQL's large object. Its OID is assigned to the bound column.
cdbi_upload_with_mime uploads the file and prepends its mime type as a header. Use HTML::Tested::ClassDBI::Upload->strip_mime_header to pull it from the data.
cdbi_upload_with_mime
cdbi_readonly boolean option can be used to make its widget readonly thus skipping its value during update. Read only widgets will not be validated.
cdbi_readonly
cdbi_primary boolean option is used to make an unique column behave as primary key. cdbi_load will use this field while retrieving the object from the database.
cdbi_primary
cdbi_load
Binds $class to $cdbi class in group $group. Special group _CDBIM_ is used as the default group.
Loads Class::DBI object using primary key field - the widget with special cdbi_bind => 'Primary'.
This method populates the rest of the bound fields with values of the loaded Class::DBI object.
Returns retrieved Class::DBI object or undef.
This function loads underlying Class::DBI objects using query function $func (e.g search) with parameters contained in @params.
search
@params
For each of those objects new HTML::Tested::ClassDBI instance is created.
Creates new database record using $obj fields.
Additional (optional) arguments are given by $args hash refernce.
Creates new database record using $obj fields in group $group.
Updates database records using $obj fields.
Calls cdbi_create or cdbi_update based on whether the database record exists already.
cdbi_create
cdbi_update
Constructs underlying Class::DBI object using $obj fields.
Deletes database record using $obj fields.
Initializes class_dbi_object field of $class_objs arrayref from the Class::DBI objects given in $cdbi_objs.
class_dbi_object
$class_objs
$cdbi_objs
Useful to avoid overhead of retrieving Class::DBI objects one by one.
Boris Sukholitko CPAN ID: BOSU boriss@gmail.com
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
HTML::Tested, Class::DBI
To install HTML::Tested::ClassDBI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTML::Tested::ClassDBI
CPAN shell
perl -MCPAN -e shell install HTML::Tested::ClassDBI
For more information on module installation, please visit the detailed CPAN module installation guide.