Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: CGI::Application and object inheritance

by donarb (Beadle)
on Jul 27, 2005 at 15:56 UTC ( [id://478661]=note: print w/replies, xml ) Need Help??


in reply to Re^2: CGI::Application and object inheritance
in thread CGI::Application and object inheritance

If you're going to be creating common methods for CGI::Application, you might want to instead create a subclass Bar which inherits from C::A. Then all of your other subclasses can inherit that functionality from Bar. I did this for a C::A I wrote. This main subclass handles sessions and authentication.

For more information on how to do this, see the C::A wiki:

http://twiki.med.yale.edu/twiki2/bin/view/CGIapp

You should also look at the C::A plugins, they add functionality without having to subclass.
  • Comment on Re^3: CGI::Application and object inheritance

Replies are listed 'Best First'.
Re^4: CGI::Application and object inheritance
by cees (Curate) on Jul 27, 2005 at 16:56 UTC

    Just to clarify what donarb is stating, here is an example of how to better structure your code:

    package Bar; use base qw(CGI::Application); sub useful_method { my $self = shift; # do something useful here } 1; package Foo; use Base qw(Bar); # By inheriting from Bar, we also inherit everything # that Bar inherits, so you don't need to specifically # mention CGI::Application in package Foo, since Bar # deals with that for you sub setup { my $self = shift; $self->run_modes(qw(runmode1 runmode2)); } sub runmode1 { my $self = shift; my $results = $self->useful_method(); ... } 1;

    So in the above example Bar would contain all of your useful methods and runmodes that all of your other application can share. Whereas Foo is the actual application that you load and run in your instance script

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://478661]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-23 08:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found