[Dbix-class] RFC: refresh / discard_changes

John Napiorkowski jjn1056 at yahoo.com
Sat May 12 20:10:37 GMT 2007


--- Marc Mims <marc at questright.com> wrote:

> It seems like the question, "How do I refresh a
> row?" comes up fairly
> often on irc and here on the list.  The answer is
> always
> $row->discard_changes.  Refreshing is the same
> function from a different
> perspective.  Rather than throwing my changes away
> (I haven't made any,
> after all), I want to "refresh" my row from storage.
> 
> I discussed it briefly with mst on irc.  He dislikes
> the name "refresh"
> and suggests, perhaps, refresh_from_storage.
> 
> A doc patch would be sufficient for users to
> discover discard_changes
> when they're looking for refresh, but a alias that
> expresses the
> alternate motivation might make application code
> more readable.
> 
> Thoughts?

Seems good to me.  I seldom have the need to refresh a
row but I can see how it might not be immediately
apparent on how to do it.  Since we have a few alias
style functions already I don't think this would
pollute the namespace.

--john


> 	-Marc
> 
> 
> 
> Here's the rough draft patch:
> 
> Index: lib/DBIx/Class/PK.pm
>
===================================================================
> --- lib/DBIx/Class/PK.pm        (revision 3310)
> +++ lib/DBIx/Class/PK.pm        (working copy)
> @@ -25,10 +25,11 @@
>    return (map { $self->{_column_data}{$_} }
> $self->primary_columns);
>  }
>  
> -=head2 discard_changes
> +=head2 discard_changes, refresh_from_storage
>  
>  Re-selects the row from the database, losing any
> changes that had
> -been made.
> +been made.  C<refresh_from_storage> is an alias for
> C<discard_changes>;
> +they do the same thing, but with different
> motivations.
>  
>  =cut
>  
> @@ -47,6 +48,10 @@
>    return $self;
>  }
>  
> +sub refresh_from_storage {
> +    shift->discard_changes(@_);
> +}
> +
>  =head2 id
>  
>  Returns the primary key(s) for a row. Can't be
> called as
> 
> 
> 
> _______________________________________________
> List:
>
http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN:
>
http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> Searchable Archive:
>
http://www.mail-archive.com/dbix-class@lists.rawmode.org/
> 



      ____________________________________________________________________________________
Park yourself in front of a world of choices in alternative vehicles. Visit the Yahoo! Auto Green Center.
http://autos.yahoo.com/green_center/ 



More information about the Dbix-class mailing list