~ubuntu-branches/ubuntu/precise/libjifty-dbi-perl/precise

« back to all changes in this revision

Viewing changes to lib/Jifty/DBI/Record.pm

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Yu
  • Date: 2010-12-25 20:52:02 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20101225205202-lnacq0abuqygrlhm
Tags: 0.64-1
* New upstream release
* Refresh copyright information
* Use new 3.0 (quilt) source format
* Standards-Version 3.9.1 (no changes)
* Drop version deps satisfied by oldstable
* POD tests are now author-only

Show diffs side-by-side

added added

removed removed

Lines of Context:
272
272
    no strict 'refs';    # We're going to be defining subs
273
273
 
274
274
    if ( not $self->can($column_name) ) {
275
 
 
276
275
        # Accessor
277
276
        my $subref;
278
 
        if ( $column->active ) {
 
277
 
 
278
        if ($column->computed) {
 
279
            $subref = sub {
 
280
                Carp::croak("column '$column_name' in $package is computed but has no corresponding method");
 
281
            };
 
282
        }
 
283
        elsif ( $column->active ) {
279
284
 
280
285
            if ( $column->readable ) {
281
286
                if (UNIVERSAL::isa(
286
291
                    $subref = sub {
287
292
                        if ( @_ > 1 ) {
288
293
                            Carp::carp
289
 
                                "Value passed to column accessor.  You probably want to use the mutator.";
 
294
                                "Value passed to column $column_name accessor.  You probably want to use the mutator.";
290
295
                        }
291
296
                        # This should be using _value, so we acl_check
292
297
                        # appropriately, except the acl checks often
308
313
                    $subref = sub {
309
314
                        if ( @_ > 1 ) {
310
315
                            Carp::carp
311
 
                                "Value passed to column accessor.  You probably want to use the mutator.";
 
316
                                "Value passed to column $column_name accessor.  You probably want to use the mutator.";
312
317
                        }
313
318
                        return ( $_[0]->_value($column_name) );
314
319
                    };
405
410
 
406
411
=head2 null_reference 
407
412
 
408
 
By default, Jifty::DBI::Record will return C<undef> for non-existant
 
413
By default, Jifty::DBI::Record will return C<undef> for non-existent
409
414
foreign references which don't exist.  That is, if each Employee
410
415
C<refers_to> a Department, but isn't required to,
411
416
C<<$model->department>> will return C<undef> for employees not in a
678
683
 
679
684
=head2 record values
680
685
 
681
 
As you've probably already noticed, C<Jifty::DBI::Record> autocreates
682
 
methods for your standard get/set accessors. It also provides you with
683
 
some hooks to massage the values being loaded or stored.
 
686
As you've probably already noticed, C<Jifty::DBI::Record> automatically
 
687
creates methods for your standard get/set accessors. It also provides you
 
688
with some hooks to massage the values being loaded or stored.
684
689
 
685
690
When you fetch a record value by calling
686
691
C<$my_record-E<gt>some_field>, C<Jifty::DBI::Record> provides the
842
847
 
843
848
    my $column_name = $column->{name}; # Speed optimization
844
849
 
 
850
    if ($column->computed) {
 
851
        return $self->$column_name;
 
852
    }
 
853
 
845
854
    # In the default case of "yeah, we have a value", return it as
846
855
    # fast as we can.
847
856
    return $self->{'values'}{$column_name}
1061
1070
sub load {
1062
1071
    my $self = shift;
1063
1072
    return unless @_ and defined $_[0];
 
1073
    Carp::carp("load called with more than one argument. Did you mean load_by_cols?") if @_ > 1;
1064
1074
 
1065
1075
    return $self->load_by_cols( id => shift );
1066
1076
}
1336
1346
 
1337
1347
This method is called after attempting to insert the record into the
1338
1348
database. It gets handed a reference to the return value of the
1339
 
insert. That'll either be a true value or a L<Class::ReturnValue>.
 
1349
insert. That will either be a true value or a L<Class::ReturnValue>.
1340
1350
 
1341
1351
Aborting the trigger merely causes C<create> to return a false
1342
1352
(undefined) value even thought he create may have succeeded. This