Posted By

willert on 09/13/08


Tagged


Versions (?)

stuff


 / Published in: Perl
 

  1. our $m;
  2. our $c;
  3.  
  4. sub fetch_user {
  5. my $id = shift;
  6. return $id if blessed $id and $id->isa('ComA::User');
  7.  
  8. my @p = ( $id );
  9.  
  10. if ( blessed $id ) {
  11. if ( $id->can('username') ) {
  12. @p = ( $id->username, { key => 'name' } );
  13. $id = 'user::name::' . $id->username;
  14. } elsif ( $id->can('id') ) {
  15. @p = ( $id->id );
  16. $id = 'user::id::' . $id->id;
  17. } else {
  18. $id = ref $id;
  19. die( "don't know how to handle user object '$id'" );
  20. }
  21. }
  22.  
  23. my $user = $m->notes( $id );
  24. return $user if $user;
  25.  
  26. $user = $c->model( 'DB::User' )->find( @p )
  27. or die "Can't fetch user $p[0]";
  28.  
  29. $m->notes( $id, $user );
  30.  
  31. return $user;
  32.  
  33. }

Report this snippet  

You need to login to post a comment.