[Jifty-commit] r5400 - in Net-Jifty: .

Jifty commits jifty-commit at lists.jifty.org
Wed May 7 20:41:10 EDT 2008


Author: sartak
Date: Wed May  7 20:41:08 2008
New Revision: 5400

Modified:
   Net-Jifty/   (props changed)
   Net-Jifty/lib/Net/Jifty/Record.pm

Log:
 r55329 at onn:  sartak | 2008-05-07 20:41:03 -0400
 Net::Jifty::Record->load


Modified: Net-Jifty/lib/Net/Jifty/Record.pm
==============================================================================
--- Net-Jifty/lib/Net/Jifty/Record.pm	(original)
+++ Net-Jifty/lib/Net/Jifty/Record.pm	Wed May  7 20:41:08 2008
@@ -50,6 +50,40 @@
     );
 }
 
+=head2 load interface, ID
+=head2 load interface, column => value
+
+Class method that loads a particular record by ID (or any column, value). Returns the record or undef.
+
+=cut
+
+sub load {
+    my $class     = shift;
+    my $interface = shift;
+    my ($column, $value);
+
+    if (@_ > 2) {
+        confess "load called with more than two arguments - it's currently limited to one (column, value) pair."
+    }
+    elsif (@_ == 2) {
+        ($column, $value) = @_;
+    }
+    elsif (@_ == 1) {
+        ($column, $value) = ('id', $_[0]);
+    }
+    else {
+        confess "load called with no ID or (column, value) pair.";
+    }
+
+    my $hash = eval { $interface->read($class->_model_class, $column, $value) };
+    return undef if !$hash;
+
+    return $class->new(
+        _interface => $interface,
+        %$hash,
+    );
+}
+
 __PACKAGE__->meta->make_immutable;
 no Moose;
 


More information about the Jifty-commit mailing list