I have an odd, funky situation. I'm writing an aggregate object module, Request.pm, that contains, among others, a CGI object. My intent is to import some of CGI's methods (per CGI's docs) into my object and have access to them as though they were methods of Request. My problem is making the imported method stick beyond the scope of my _init() method. Here's a sample:
sub new { #object blessing stuff skipped here... $self->_init(@_); return $self; } sub _init { my $self = shift; #the following creates the CGI object, importing the #method param() into current scope, _init() $self->{'query'} = new CGI qw(param); #...etc... }
After having done this, the user only needs to do...
my ($comment) = $requestobj->param('comment');
...to access the value of the form variable "comment". I've tried different methods to make this work, but nothing has seemed to work short of creating a stub method in Request to forward any parameters and return context to the CGI::param() method.

Is there a way, while in the scope of _init(), to assign the imported method param() to the Request object? Would I have to use, perhaps, a sub reference? Would I have to rely on AUTOLOAD to form a forward call to any imported methods? I know that when _init() goes out of scope, the methods imported from CGI fail to exist; I want these methods to be sticky.

I am a-thoroughly confused. Thanks for any help.

-Shawn / (Ph) Phaysis
If idle hands are the tools of the devil, are idol tools the hands of god?


In reply to Importing CGI methods into a subclass as a class method by Phaysis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.