Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

REST::Application not finding handler

by hesco (Deacon)
on Aug 17, 2009 at 20:30 UTC ( [id://789272]=perlquestion: print w/replies, xml ) Need Help??

hesco has asked for the wisdom of the Perl Monks concerning the following question:

How do I overload REST::Application->new() ???

I have a module which looks something like this:

package MyApp::RESTful; use warnings; use strict; use REST::Application; use base 'REST::Application'; sub new { my $self = shift; my $args = shift; my $app = {}; $app->{'dbh'} = DBI->connect(); $app->{'cfg'} = Config::Simple->new(); $app->{'__defaultQuery'} = CGI->new(); . . . . . . bless $app, $self; return $app; } sub setup { my $self = shift; $self->resourceHooks( qr{/sd/agent/create/(.*)$} => '_AgentCreate', qr{/sd/agent/password/change/(.*)$} => '_AgentPWChange', qr{/sd/agent/logout/(.*)$} => '_AgentLogOut', qr{/sd/agent/stats/(.*)$} => '_AgentJobStats', qr{/sd/agent/authentication/(.*)$} => '_AgentAuthenticate' ); }
I'm running tests on this module which look like this:

my @REST_methods = qw( new query defaultQueryObject resourceHooks extr +aHandlerArgs getPathInfo getRealRequestMethod getRequestMethod loadRe +source getHandlerArgs callHandler getMatchText checkMatch getLastMatc +hPath getLastMatchPattern run getHeaders addRepresentation headerType + header resetHeader setRedirect setup preRun postRun defaultResourceH +andler _getHandlerFromHook makeHandlerFromRef makeHandlerFromClass be +stContentType simpleContentNegotiation scoreType getContentPrefs getA +cceptHeader _getLastRegexMatches _setLastRegexMatches ); foreach my $method ( @REST_methods ){ can_ok($myapp, $method); }
which seems to indicate that $myapp can perform all of the methods in its base class REST::Application. But for some reason, it does not seem to be running the handler specified in my setup() call. It does seem to be running both preRun() and postRun() just fine, but I'm not seeing callHandler() do its thing with my custom code identified in the call to ->resourceHooks().

I have not found much literature on this module beyond the perldoc. Are folks actually using REST::Application and if so, can anyone advise me how to make it work, please?

-- Hugh

UPDATE:

I also wrote the author asking the following:

Does REST::Application still only work with Apache 1.3, as suggested in the article here: http://perlmonks.com/?node_id=562705

Is it safe to assume that if I'm not using mod_perl, but cgi instead that I don't need:

use Apache; use Apache::Constants qw(:common); sub handler { __PACKAGE__->new(request => $r)->run(); return OK; }
if( $lal && $lol ) { $life++; }

Replies are listed 'Best First'.
Re: REST::Application not finding handler
by Anonymous Monk on Aug 18, 2009 at 01:47 UTC
    How do I overload REST::Application->new() ???

    Read perltoot

    sub new { my $self = shift; my $app = $self->SUPER::new(@_); #~ $app->{'dbh'} = DBI->connect(); #~ $app->{'cfg'} = Config::Simple->new(); return $app; }
    But there is no need to overload new since setup is provided for that purpose.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://789272]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-26 06:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found