X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FHelper%2FPresenter.pm;h=1dae8ccbdac531fddfbc83e01eb020c158c5f200;hb=bfa674c9d4edc551afa6e27aac6f684a7b8cb656;hp=48502548fa970f04388e52549eed6652126f60ba;hpb=972b87711cb3c7543d585ceedca0eda2058aa6d7;p=kivitendo-erp.git diff --git a/SL/DB/Helper/Presenter.pm b/SL/DB/Helper/Presenter.pm index 48502548f..1dae8ccbd 100644 --- a/SL/DB/Helper/Presenter.pm +++ b/SL/DB/Helper/Presenter.pm @@ -17,7 +17,19 @@ sub AUTOLOAD { return if $method eq 'DESTROY'; - return $self->[0]->$method($self->[1], @args); + eval "require $self->[0]"; + + splice @args, -1, 1, %{ $args[-1] } if @args && (ref($args[-1]) eq 'HASH'); + + if (my $sub = $self->[0]->can($method)) { + return $sub->($self->[1], @args); + } +} + +sub can { + my ($self, $method) = @_; + eval "require $self->[0]"; + $self->[0]->can($method); } 1; @@ -32,25 +44,25 @@ SL::DB::Helper::Presenter - proxy class to allow models to access presenters =head1 SYNOPSIS - # assuming SL::Presemter::Part exists + # assuming SL::Presenter::Part exists # and contains a sub link_to($class, $object) {} SL::DB::Part->new(%args)->presenter->link_to =head1 DESCRIPTION -When coding controller one often encounters objects that are not crucial to the -current task, but must be presented in some form to the user. Instead of +When coding controllers one often encounters objects that are not crucial to +the current task, but must be presented in some form to the user. Instead of recreating that all the time the C namepace was introduced to hold such code. Unfortunately the Presenter code is designed to be stateless and thus acts _on_ objects, but can't be instanced or wrapped. The early band-aid to that was to export all sub-presenter calls into the main presenter namespace. Fixing it -would have meant to access presenter functions like this: +would have meant accessing presenter functions like this: SL::Presenter::Object->method($object, %additional_args) -which is extremely inconvenient. +which is extremely inconvenient. This glue code allows C instances to access routines in their presenter without additional boilerplate. C contains a @@ -59,8 +71,8 @@ class. All calls on this will then be forwarded to the appropriate presenter. =head1 INTERNAL STRUCTURE -The proxy objects created are lightweight blessed arrayrefs instead of the usual blessed -hashrefs. They only store two elements: +The created proxy objects are lightweight blessed arrayrefs instead of the +usual blessed hashrefs. They only store two elements: =over 4