Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Commit

Permalink
Added files
Browse files Browse the repository at this point in the history
  • Loading branch information
kloevschall committed Mar 5, 2015
1 parent 79de82c commit e7d4c3c
Show file tree
Hide file tree
Showing 12 changed files with 1,038 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bin/app.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env perl
use Dancer;
use PrimoServices;
dance;
27 changes: 27 additions & 0 deletions environments/development.yml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# configuration file for development environment

# the logger engine to use
# console: log messages to STDOUT (your console where you started the
# application server)
# file: log message to a file in log/
logger: "console"

# the log level for this environment
# core is the lowest, it shows Dancer's core log messages as well as yours
# (debug, info, warning and error)
log: "core"

# should Dancer consider warnings as critical errors?
warnings: 1

# should Dancer show a stacktrace when an error is caught?
show_errors: 1

# auto_reload is a development and experimental feature
# you should enable it by yourself if you want it
# Module::Refresh is needed
#
# Be aware it's unstable and may cause a memory leak.
# DO NOT EVER USE THIS FEATURE IN PRODUCTION
# OR TINY KITTENS SHALL DIE WITH LOTS OF SUFFERING
auto_reload: 0
17 changes: 17 additions & 0 deletions environments/production.yml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# configuration file for production environment

# only log warning and error messages
log: "warning"

# log message to a file in logs/
logger: "file"

# don't consider warnings critical
warnings: 0

# hide errors
show_errors: 0

# cache route resolution for maximum performance
route_cache: 1

64 changes: 64 additions & 0 deletions lib/PrimoServices.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package PrimoServices;
use Dancer 1.3132 ':syntax';
use Dancer::Exception ':all';

use PrimoServices::Dispatcher;

use Time::HiRes();
use Benchmark(':hireswallclock');

# http://semver.org/
# X.Y.Z (Major.Minor.Patch)
use version; our $VERSION = version->declare("v2.2.0");

#
# Route handlers
#

get qr{.*} => sub {

my $data;

# Parse and reply to the request
#$data = PrimoServices::Dispatcher::handle_request();

try {
my $execution_time = timeit( 1, sub{
$data = PrimoServices::Dispatcher::handle_request();
});

# Calculate the total execution time of the call
$data->{appExecutionTime} = sprintf "%.3fs", $execution_time->real;
}
catch {
status 500;
$data->{error} = 'PrimoServices';
$data->{exception} = $_;
};

# Insert the request into the response (in development)
$data->{request} = params if config->{environment} eq 'development';

# Delete request_lookup_table (outside development)
delete $data->{request_lookup_table} if config->{environment} ne 'development';

# Count requested and returned number of IDs
$data->{totalItems} = param_array 'id';
$data->{totalItemsReturned} = @{$data->{items}};

# Name and version
$data->{appName} = config->{appname} . ' ' . $VERSION->normal();

# Set the serializer to either JSONP or JSON
if ( params->{callback} ) {
set serializer => 'JSONP';
}
else {
set serializer => 'JSON';
}

# Serialize...
return $data;
};

true;
Loading

0 comments on commit e7d4c3c

Please sign in to comment.