Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^3: CGI::Application and object inheritance

by donarb (Beadle)
on Jul 27, 2005 at 15:56 UTC ( #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:

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?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2022-01-17 01:12 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (50 votes). Check out past polls.