[Jifty-commit] r5874 - in Jifty-DBI/trunk: lib/Jifty/DBI

Jifty commits jifty-commit at lists.jifty.org
Fri Sep 19 19:01:14 EDT 2008

Author: ruz
Date: Fri Sep 19 19:01:14 2008
New Revision: 5874

   Jifty-DBI/trunk/   (props changed)

 r5894 at cubic-pc:  cubic | 2008-09-19 23:01:45 +0400
 * cache load attempts in new_item method
 * update documentation

Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm
--- Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm	Fri Sep 19 19:01:14 2008
@@ -987,9 +987,16 @@
 =head2 new_item
 Should return a new object of the correct type for the current collection.
+L</record_class> method is used to determine class of the object.
+Each record class at least once is loaded using require. This method is
+called each time a record fetched so load atemts are cached to avoid
+penalties. If you're sure that all record classes are loaded before
+first use then you can override this method.
+{ my %cache = ();
 sub new_item {
     my $self  = shift;
     my $class = $self->record_class();
@@ -997,15 +1004,17 @@
     die "Jifty::DBI::Collection needs to be subclassed; override new_item\n"
         unless $class;
-    warn "$self $class\n" if $class =~ /::$/;
-    $class->require();
+    unless ( exists $cache{$class} ) {
+        $class->require;
+        $cache{$class} = undef;
+    }
     return $class->new( $self->_new_record_args );
+} }
 =head2 record_class
 Returns the record class which this is a collection of; override this
-to subclass.  Or, pass it the name of a class an an argument after
+to subclass.  Or, pass it the name of a class as an argument after
 creating a C<Jifty::DBI::Collection> object to create an 'anonymous'
 collection class.

More information about the Jifty-commit mailing list