Class::Inflate - Inflate HASH Object from Values in Database


Class-Inflate documentation  | view source Contained in the Class-Inflate distribution.

Index


NAME

Top

Class::Inflate - Inflate HASH Object from Values in Database

SYNOPSIS

Top

  # in package
  package Some::Package::Name;
  use Class::Inflate (
      $table_one => {
          key => \@primary_key_fields,
	  methods => {
	      $method_one => $field_one,
	      $method_two => {
	          inflate => sub { join('-', @_) },
		  deflate => sub { split(/-/, shift(), 2) },
		  fields  => [$field_two, $field_three],
	      },
	  },
      },
      $table_two => {
          key => \@primary_key_fields,
	  join => {
	      $table_one => {
	          $field_one => $field_1,
	      },
	  },
	  methods => {
	      $method_$three => $field_2,
	  }
      },
  );

  # in script
  use Some::Package::Name;
  my @objects = Some::Package::Name->inflate({$field_one => $value});

DESCRIPTION

Top

Allows for any blessed HASH object to be populated from a database, by describing table relationships to each method.

When specifying a database relationship to a method, there are several hooks you can specify:

inflate

Called when converting database values into method values. Receives the values from the database fields specified. The return values are passed to the object accessor for the method.

postinflate

Called after object has been inflated. The variable $::OBJECT is available, and contains the object being populated.

The database handle used for inflation is available as the first argument to postinflate.

deflate

Called when converting method values into database values. Receives the values from the object accessor for the method. The return values are passed to the database fields specified.

The database fields are specified as an ARRAY reference of field names, if any of the hooks are used.

EXPORT

Exports inflate method into caller's namespace.

SEE ALSO

Top

Tangram(3), Class::DBI(3), which have similar concepts, but are tied more closely to database structure.

AUTHOR

Top

Nathan Gray, <kolibrie@cpan.org>

COPYRIGHT AND LICENSE

Top


Class-Inflate documentation  | view source Contained in the Class-Inflate distribution.