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::DBI::LazyInflate(3) User Contributed Perl Documentation Class::DBI::LazyInflate(3)

Class::DBI::LazyInflate - Defer Inflating Of Columns Until They Are Used

  package MyData;
  use base qw(Class::DBI);
  use Class::DBI::LazyInflate;
  use DateTime;
  use DateTime::Format::MySQL;

  __PACKAGE__->has_lazy(
    'lastmod', 'DateTime',
    inflate => sub { DateTime::Format::MySQL->parse_datetime(shift) },
    deflate => sub { DateTime::Format::MySQL->format_datetime(shift) },
  );

  my $obj = MyData->retrieve($key); # lastmod is not inflated yet
  $obj->lastmod()->year();          # now it is.

  $obj->lastmod(DateTime->now());

  # Specify another Class::DBI type as a column:
  __PACKAGE__->has_lazy(cdbi_field => 'MyData');

Class::DBI::LazyInflate is a utility class that allows you to create DBI columns that only inflate to an object when it is required. When a row is fetched, columns specified via has_lazy() is wrapped by Data::Lazy, such that it is inflated only when the column is actually used.

As seen in the SYNOPSIS section, one application of this class is for columns that inflate to objects that are costly to create, such as DateTime. Class::DBI::LazyInflate allows you defer materialization of such objects until when you really need it.

has_lazy() declares that column is to be inflated lazily, and is installed to the calling package's namespace upon call to "use Class::DBI::LazyInflate". The arguments are exactly the same as has_a().

If inflate is not specified, it will lazily perform the default inflate procedure that Class::DBI uses.

Copyright (c) 2004-2005 Daisuke Maki <dmaki@cpan.org>

Class::DBI Data::Lazy

For DateTime objects, you may also be interested in DateTime::LazyInit.

2005-10-18 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.