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

NAME

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

SYNOPSIS

  # 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

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

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

AUTHOR

Nathan Gray, <kolibrie@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2006, 2008 by Nathan Gray

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.