Not sure how best to word the question - let me give more details.

I'm trying to move runmode subs, which I'm going to call 'actions', into
their own class/file/package.

While I could probably just 'require ActionThingy.pl', would prefer to 'use
ActionThingy;' so its more OO-ish. Enables parent action class for standard
tasks that many actions might do (ex. check auth level). OO Actions could
make DB connections only if necessary (not all of my run modes require DB
connection overhead - so setup() isn't granular enough).

Thinking well in the future - it's conceivable that somehow the actions
could be autoloadable to save some compile time due to unused code when
there is only a single run_mode being called.

The problem I'm having is how to specify a reference to the workhorse
subroutine inside the action - called doPerform().

-----
package JobAgent;
use base 'PerlAppFramework';

use ActionShowList;
my $action = new ActionShowList( $self->query() );

   $self->run_modes(
           'mode1' => \&showform,
           'mode2' => \{$action->doPerform()}  # naive attempt which barfs
   );
Barf error mesg:
[Thu Sep 27 15:08:30 2001] JobAgent: Error executing run mode 'mode2'.  Eval
of code '$self->SCALAR(0x250564)' resulted in error: [Thu Sep 27 15:08:30
2001] JobAgent: Can't locate object method "SCALAR" via package "JobAgent"
at (eval 12) line 1, <STDIN> chunk 1.


I've searched perlmonks.org and of course the perltoot and perlobj -> but
can't seem to find out how to create a reference to a method of an object.

Any help will be appreciated. :-)

Thanks,
Tim
BTW - if anybody does both Perl and Java stuff, part of this discussion is
inspired from work I've done using Struts
(http://jakarta.apache.org/struts/)


------
package ActionShowList;

sub new {
        my ($this, $q) = @_;
        my $class = ref($this) || $this;
        my $self = {
                'QUERY' => $q
                };
        bless $self, $class;
        return $self;
}

sub query {
 my $self = shift;
 return $self->{'QUERY'};

}

sub doPerform {
   my $self = shift;
   # Get CGI query object
   my $q = $self->query();
   my $widgetcode = $q->param("widgetcode");
   my $output = '';
   $output .= $q->start_html(-title => 'List of Matching Widgets');
   $output .= "listing of widget thingies = " . $widgetcode;
   $output .= $q->end_html();
   return $output;
}

1;


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to