in reply to REST::Application not finding handler
Read perltoot
But there is no need to overload new since setup is provided for that purpose.sub new { my $self = shift; my $app = $self->SUPER::new(@_); #~ $app->{'dbh'} = DBI->connect(); #~ $app->{'cfg'} = Config::Simple->new(); return $app; }
#!/usr/bin/perl -- package MyApp::RESTful; { use warnings; use strict; use REST::Application; use base 'REST::Application'; sub new { my $self = shift; my $app = $self->SUPER::new(@_); #~ $app->{'dbh'} = DBI->connect(); #~ $app->{'cfg'} = Config::Simple->new(); 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' ); $self->header( -type => 'text/plain' ); } # printf "sub %s { qq'%s \@_\\n' }\n", ($_) x 2 for qw[ _AgentCreate _ +AgentPWChange _AgentLogOut _AgentJobStats _AgentAuthenticate ]; sub _AgentCreate { qq'_AgentCreate @_\n' } sub _AgentPWChange { qq'_AgentPWChange @_\n' } sub _AgentLogOut { qq'_AgentLogOut @_\n' } sub _AgentJobStats { qq'_AgentJobStats @_\n' } sub _AgentAuthenticate { qq'_AgentAuthenticate @_\n' } sub loadResource { my ($self, $path, @extraArgs) = @_; $path ||= $self->getMatchText(); my $handler = sub { $self->defaultResourceHandler(@_) }; warn "path $path "; warn "handler $handler default "; my $matches = []; # Loop through the keys of the hash returned by resourceHooks( +). Each of # the keys is a regular expression, see if the current path in +fo matches # that regular expression. Save the parent matches for passin +g into the # handler. for my $pathRegex (keys %{ $self->resourceHooks() }) { warn "pathRegex $path $pathRegex "; if ($self->checkMatch($path, $pathRegex)) { $handler = $self->_getHandlerFromHook($pathRegex); last; } } warn "handler $handler "; return $self->callHandler($handler, @extraArgs); } } package main; { $ENV{PATH_INFO} = '/sd/agent/create/something'; MyApp::RESTful->new->run(); use DDS; Dump( MyApp::RESTful->new->resourceHooks() ); } __END__ path /sd/agent/create/something at 789272.pl line 47. handler CODE(0x1fc4de4) default at 789272.pl line 48. pathRegex /sd/agent/create/something (?-xism:/sd/agent/create/(.*)$) +at 789272.pl line 56. handler CODE(0x2006108) at 789272.pl line 62. Content-Type: text/plain; charset=ISO-8859-1 _AgentCreate MyApp::RESTful=HASH(0x20054b4) something $HASH1 = { "(?-xism:/sd/agent/authentication/(.*)\$)" => '_AgentAuthe +nticate', "(?-xism:/sd/agent/create/(.*)\$)" => '_AgentCreat +e', "(?-xism:/sd/agent/logout/(.*)\$)" => '_AgentLogOu +t', "(?-xism:/sd/agent/password/change/(.*)\$)" => '_AgentPWCha +nge', "(?-xism:/sd/agent/stats/(.*)\$)" => '_AgentJobSt +ats' };
|
|---|