• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

lib/Class/DBI/H18-Oct-2005-11340

t/H18-Oct-2005-8962

Build.PLH A D18-Oct-2005886 3728

ChangesH A D18-Oct-2005614 2721

MANIFESTH A D18-Oct-2005133 109

META.ymlH A D18-Oct-2005370 1615

Makefile.PLH A D18-Oct-2005443 1513

READMEH A D18-Oct-20051.8 KiB5339

README

1NAME
2    Class::DBI::LazyInflate - Defer Inflating Of Columns Until They Are Used
3
4SYNOPSIS
5      package MyData;
6      use base qw(Class::DBI);
7      use Class::DBI::LazyInflate;
8      use DateTime;
9      use DateTime::Format::MySQL;
10
11      __PACKAGE__->has_lazy(
12        'lastmod', 'DateTime',
13        inflate => sub { DateTime::Format::MySQL->parse_datetime(shift) },
14        deflate => sub { DateTime::Format::MySQL->format_datetime(shift) },
15      );
16
17      my $obj = MyData->retrieve($key); # lastmod is not inflated yet
18      $obj->lastmod()->year();          # now it is.
19
20      $obj->lastmod(DateTime->now());
21
22      # Specify another Class::DBI type as a column:
23      __PACKAGE__->has_lazy(cdbi_field => 'MyData');
24
25DESCRIPTION
26    Class::DBI::LazyInflate is a utility class that allows you to create DBI
27    columns that only inflate to an object when it is required. When a row
28    is fetched, columns specified via has_lazy() is wrapped by Data::Lazy,
29    such that it is inflated only when the column is actually used.
30
31    As seen in the SYNOPSIS section, one application of this class is for
32    columns that inflate to objects that are costly to create, such as
33    DateTime. Class::DBI::LazyInflate allows you defer materialization of
34    such objects until when you really need it.
35
36METHODS
37  has_lazy($col, $class, inflate => ..., deflate => ...)
38    has_lazy() declares that column is to be inflated lazily, and is
39    installed to the calling package's namespace upon call to "use
40    Class::DBI::LazyInflate". The arguments are exactly the same as has_a().
41
42    If inflate is not specified, it will lazily perform the default inflate
43    procedure that Class::DBI uses.
44
45AUTHOR
46    Copyright (c) 2004-2005 Daisuke Maki <dmaki@cpan.org>
47
48SEE ALSO
49    Class::DBI Data::Lazy
50
51    For DateTime objects, you may also be interested in DateTime::LazyInit.
52
53