1 package SL::DB::Helper::Presenter;
 
   6   # lightweight: 0: class, 1: object
 
   7   bless [ $_[1], $_[2] ], $_[0];
 
  13   my ($self, @args) = @_;
 
  15   my $method = $AUTOLOAD;
 
  18   return if $method eq 'DESTROY';
 
  20   return $self->[0]->$method($self->[1], @args);
 
  31 SL::DB::Helper::Presenter - proxy class to allow models to access presenters
 
  35   # assuming SL::Presenter::Part exists
 
  36   # and contains a sub link_to($class, $object) {}
 
  37   SL::DB::Part->new(%args)->presenter->link_to
 
  41 When coding controllers one often encounters objects that are not crucial to
 
  42 the current task, but must be presented in some form to the user. Instead of
 
  43 recreating that all the time the C<SL::Presenter> namepace was introduced to
 
  46 Unfortunately the Presenter code is designed to be stateless and thus acts _on_
 
  47 objects, but can't be instanced or wrapped. The early band-aid to that was to
 
  48 export all sub-presenter calls into the main presenter namespace. Fixing it
 
  49 would have meant accessing presenter functions like this:
 
  51   SL::Presenter::Object->method($object, %additional_args)
 
  53 which is extremely inconvenient.
 
  55 This glue code allows C<SL::DB::Object> instances to access routines in their
 
  56 presenter without additional boilerplate. C<SL::DB::Object> contains a
 
  57 C<presenter> call for all objects, which will return an instance of this proxy
 
  58 class. All calls on this will then be forwarded to the appropriate presenter.
 
  60 =head1 INTERNAL STRUCTURE
 
  62 The created proxy objects are lightweight blessed arrayrefs instead of the
 
  63 usual blessed hashrefs. They only store two elements:
 
  67 =item * The presenter class
 
  69 =item * The invocing object
 
  73 Further delegation is done with C<AUTOLOAD>.
 
  81 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>