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.
#!/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' };

In reply to Re: REST::Application not finding handler by Anonymous Monk
in thread REST::Application not finding handler by hesco

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.