Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: CGI::Application and object inheritance

by spork (Monk)
on Jul 27, 2005 at 15:39 UTC ( #478648=note: print w/replies, xml ) Need Help??


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

The code sample was condensed into generic form. In the real world the BAR set will be a group of common attributes and methods that will be used and extended be several FOOs. I believe this is a case of ISA, but OO use is new ground for me. Thank you for your help.
  • Comment on Re^2: CGI::Application and object inheritance

Replies are listed 'Best First'.
Re^3: CGI::Application and object inheritance
by donarb (Beadle) on Jul 27, 2005 at 15:56 UTC
    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.

      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://478648]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2023-03-31 15:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (76 votes). Check out past polls.

    Notices?