On October 17, 2003 08:21 am, 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.
That's the first problem. I'm surprised that these are even called
correctly.
> WebApp/Print.pm
> --------------------------------------------
> package WebApp::Print;
> use Exporter;
>
> @EXPORT = qw(mode1 mode2 mode3);
Should be @EXPORT_OK rather than @EXPORT, but that's not the problem.
> 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.
Which is exactly what C::A expects you to do - put the functions in the
same module as everything else. There are ways to do what you want to
do - "right" ways and "wrong" ways.
> The question is: how can I get the content of CGI::Application object
> from included module's subroutine?
Here are some examples:
sub setup {
my $self = shift;
$self->start_mode('mode1');
$self->run_modes(
mode1 => sub { my $self = shift;
WebApp::Print::mode1($self, @_); },
mode2 => sub { WebApp::Print::mode2(@_); },
mode3 => \&WebApp::Print::mode3,
);
}
Each of these do somewhat of the same thing. However, also realise
that WebApp::Print is not WebApp, so calling the object "$self" is
misleading. Calling it "$app" would be more accurate - because you're
no longer in the WebApp object.
---------------------------------------------------------------------
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.