The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

SYNOPSIS

  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;
        

DESCRIPTION

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.

METHODS

$class->bind_to_class_dbi($cdbi_class)

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.

$obj->cdbi_load

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.

$obj->cdbi_create($args)

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.

$obj->cdbi_update($args)

Updates database records using $obj fields.

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

$obj->cdbi_create_or_update($args)

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

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

$obj->cdbi_construct

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

$obj->cdbi_delete

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.

AUTHOR

        Boris Sukholitko
        CPAN ID: BOSU
        
        boriss@gmail.com
        

COPYRIGHT

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.

SEE ALSO

HTML::Tested, Class::DBI