The call to run_modes can take a hash as it's parameter. This keys of this
hash are the names of the run modes and the values are either the names of the
modes, or they are references to the subs for those modes.
It sounds to me like you're going to need to create a few closures. Perl5
doesn't have a way to pass a reference to methods (that's coming in Perl6) so
this is how it's done.
<code>
package WebApp;
use base 'CGI::Application';
use WebApp::Print;
[...]
sub setup {
my $self = shift;
$self->start_mode('mode1');
$self->run_modes(
mode1 => sub( WebApp::Print->mode1(@_) },
mode2 => sub( WebApp::Print->mode2(@_) },
mode3 => sub( WebApp::Print->mode3(@_) },
);
}
</code>
This will use the methods of WebApp::Print as the run modes for this app. This
does raise the question of why you want to put those methods in another app.
If they are being used by other apps then this might make sense, but then
couldn't you redesign your structure so that all you need is multiple instance
scripts and not multiple modules?
Does that help.
Michael Peters
Venzia
Wojciech Pietron wrote
> Hi,
>
> does anybody can help me with bases of Object Oriented Perl? I
> believe this is a simple question.
>
> Have a look:
>
> WebApp.pm
> --------------------------------------------
> package WebApp;
> use base 'CGI::Application';
> use WebApp::Print qw|mode1 mode2 mode3|;
>
> [...]
>
> sub setup {
> my $self = shift;
> $self->start_mode('mode1');
> $self->run_modes([ qw|mode1 mode2 mode3| ]);
> }
> --------------------------------------------
>
> Now I have mode1, mode2 and mode3 subroutines defined in
> WebApp::Print module.
>
> WebApp/Print.pm
> --------------------------------------------
> package WebApp::Print;
> use Exporter;
>
> @EXPORT = qw(mode1 mode2 mode3);
>
> sub mode1 {
> my $self = shift;
> [...]
> }
>
> --------------------------------------------
>
> It looks like $self contains nothing. When I include mode1, mode2 and
> mode3 subroutines into WebApp.pm all works OK.
>
> The question is: how can I get the content of CGI::Application object
> from included module's subroutine?
>
> Best regards,
> Wojciech Pietron
>
> ---------------------------------------------------------------------
> Web Archive: http://www.mail-archive.com/suppressed/
> http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
> To unsubscribe, e-mail: suppressed
> For additional commands, e-mail: suppressed
------- End of Original Message -------
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.