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

NAME

DBIx::SQLEngine::Record::Class - Factory for Record Classes

SYNOPSIS

Setup: Several ways to create a class.

  $sqldb = DBIx::SQLEngine->new( ... );
  
  $class_name = $sqldb->record_class( $table_name, @traits );
  
  $sqldb->record_class( $table_name, $class_name, @traits );

Basics: Common operations on a record.

  $record = $class_name->fetch_record( $primary_key );
  
  @records = $class_name->fetch_select(%clauses)->records;
  
  $record = $class_name->new_with_values(somefield => 'My Value');
  
  print $record->get_values( 'somefield' );
  $record->change_values( somefield => 'New Value' );

  $record->insert_record();
  
  $record->update_record();
  
  $record->delete_record();

DESCRIPTION

DBIx::SQLEngine::Record::Class is a factory for Record classes.

You can use this package to create a class whose instances represent each of the rows in a SQL database table.

CLASS INSTANTIATION

Subclass Factory

import
  package My::Record;
  use DBIx::SQLEngine::Record::Class '-isasubclass';
  use DBIx::SQLEngine::Record::Class '-isasubclass', @Traits;

Allows for a simple declaration of inheritance.

Record Class Creation

new_subclass()
  DBIx::SQLEngine::Record::Class->new_subclass( %options ) : $class_name

Subclass constructor. Accepts a hash of options with the following keys:

'name'

If you do not supply a class name, one is generated based on the table name, which must be provided.

If the class name does not contain a "::" package separator, it is prepended with DBIx::SQLEngine::Record::Auto:: to keep the namespace conflict-free.

'table'

You may provde a DBIx::SQLEngine::Schema::Table object or create the class without it and initialize it later.

'traits'

You may pass a reference to one or more trait names as a "traits" argument.

subclass_for_table()
  DBIx::SQLEngine::Record::Class->subclass_for_table( $table, $name, @traits ) : $class_name

Convenience method for common parameters. You are expected to provde a DBIx::SQLEngine::Schema::Table object.

Cross-constructors from other objects:

SQLEngine->record_class()
  $sqldb->record_class( $tablename ) : $class_name
  $sqldb->record_class( $tablename, $name ) : $class_name
  $sqldb->record_class( $tablename, $name, @traits ) : $class_name

Convenience method to create a record class with the given table name.

Table->record_class()
  $table->record_class( ) : $class_name
  $table->record_class( $name ) : $class_name
  $table->record_class( $name, @traits ) : $class_name

Convenience method to create a record class for a given table object.

generate_subclass_name_for_table()

Called internally by new_subclass() if no class name is provided.

RECORD CLASS TRAITS

Depending on application, there are several different sets of features that one might or might not wish to have available on their record class.

Included Trait Classes

The following trait classes are included with this distribution:

Accessors

Generates methods for getting and setting values in each record object.

Cache

Provides a caching layer to avoid repeated selections of the same information.

Hooks

Adds ok_, pre_, and post_ hooks to key methods. Any number of code refs can be registered to be called at key times, by class or for specific instances.

Accessing Packages

base_class
  $factory->base_class() : $base_class
require_package
  $factory->require_package( $package_name )

Uses require() to load the named package.

get_trait_package()
  $factory->get_trait_package($subclass) : ($name, $package, $trait)

Composing Trait Classes

base_class_with_traits
  $factory->base_class_with_traits() : $base_class
  $factory->base_class_with_traits( @traits ) : $class_name

Instead of forcing use of NEXT, with a slower redispatch method, we're going to build an ad-hod class hierarchy. Because some of the methods call SUPER methods, they need to be evaluated repeatedly in each composed subclass.

Trait Subclass Internals

import_self_trait()

Used by trait packages to construct simple subclasses.

SEE ALSO

See DBIx::SQLEngine for the overall interface and developer documentation.

See DBIx::SQLEngine::Docs::ReadMe for general information about this distribution, including installation and license information.