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

Re^2: CGI::Application and object inheritance

by spork (Monk)
on Jul 27, 2005 at 15:39 UTC ( [id://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:

    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?

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2024-06-12 18:26 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.