Boris Sukholitko > HTML-Tested-ClassDBI-0.23 > HTML::Tested::ClassDBI



Annotate this POD


Open  0
View/Report Bugs
Module Version: 0.23   Source  


HTML::Tested::ClassDBI - Enhances HTML::Tested to work with Class::DBI


  package MyClass;
  use base 'HTML::Tested::ClassDBI';
                  , id => cdbi_bind => "Primary");
                  , x => cdbi_bind => "");
        , x => cdbi_upload => "largeobjectoid");

  # And later somewhere ...
  # Query and load underlying Class::DBI:
  my $list = MyClass->query_class_dbi(search => x => 15);

  # or sync it to the database:


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.

After calling bind_to_class_dbi you would be able to automatically synchronize between HTML::Tested::ClassDBI instance and underlying Class::DBI.



Binds $class to $cdbi_class, by going over all fields declared with cdbi_bind or cdbi_upload option.

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_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_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.

$class->bind_to_class_dbi_gr($group, $cdbi_class)

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.

$class->query_class_dbi($func, @params)

This function loads underlying Class::DBI objects using query function $func (e.g search) with parameters contained in @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.

$class->cdbi_create_gr($group, $args)

Creates new database record using $obj fields in group $group.


Updates database records using $obj fields.

Additional (optional) arguments are given by $args hash refernce.


Calls cdbi_create or cdbi_update based on whether the database record exists already.

Additional (optional) arguments are given by $args hash refernce.


Constructs underlying Class::DBI object using $obj fields.


Deletes database record using $obj fields.

$class->cdbi_set_many($class_objs, $cdbi_objs)

Initializes class_dbi_object field of $class_objs arrayref from the Class::DBI objects given in $cdbi_objs.

Useful to avoid overhead of retrieving Class::DBI objects one by one.


        Boris Sukholitko
        CPAN ID: BOSU


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

syntax highlighting: