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'
);
}
####
my @REST_methods = qw( new query defaultQueryObject resourceHooks extraHandlerArgs getPathInfo getRealRequestMethod getRequestMethod loadResource getHandlerArgs callHandler getMatchText checkMatch getLastMatchPath getLastMatchPattern run getHeaders addRepresentation headerType header resetHeader setRedirect setup preRun postRun defaultResourceHandler _getHandlerFromHook makeHandlerFromRef makeHandlerFromClass bestContentType simpleContentNegotiation scoreType getContentPrefs getAcceptHeader _getLastRegexMatches _setLastRegexMatches );
foreach my $method ( @REST_methods ){
can_ok($myapp, $method);
}
####
use Apache;
use Apache::Constants qw(:common);
sub handler {
__PACKAGE__->new(request => $r)->run();
return OK;
}