GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Class::Inflate(3) User Contributed Perl Documentation Class::Inflate(3)

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

  # 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});

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.

Exports "inflate" method into caller's namespace.

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

Nathan Gray, <kolibrie@cpan.org>

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.

2022-04-08 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.