| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Articulate::Syntax::Routes; | 
| 2 | 5 |  |  | 5 |  | 22 | use strict; | 
|  | 5 |  |  |  |  | 8 |  | 
|  | 5 |  |  |  |  | 147 |  | 
| 3 | 5 |  |  | 5 |  | 195 | use warnings; | 
|  | 5 |  |  |  |  | 8 |  | 
|  | 5 |  |  |  |  | 101 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | # use Dancer qw(:syntax); | 
| 6 | 5 |  |  | 5 |  | 21 | use Exporter::Declare; | 
|  | 5 |  |  |  |  | 7 |  | 
|  | 5 |  |  |  |  | 34 |  | 
| 7 | 5 |  |  | 5 |  | 5786 | use Articulate::Service; | 
|  | 5 |  |  |  |  | 7 |  | 
|  | 5 |  |  |  |  | 27 |  | 
| 8 |  |  |  |  |  |  | default_exports qw( | 
| 9 |  |  |  |  |  |  | any get post patch del put options | 
| 10 |  |  |  |  |  |  | ); | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | #  request upload uploads captures param params splat | 
| 13 |  |  |  |  |  |  | #  config var session template | 
| 14 |  |  |  |  |  |  | #  redirect forward halt pass send_error status | 
| 15 |  |  |  |  |  |  | # ); # the first line will stay, everything else will find its way into framework | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 5 |  |  | 5 |  | 1288 | no warnings 'redefine'; | 
|  | 5 |  |  |  |  | 9 |  | 
|  | 5 |  |  |  |  | 415 |  | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | sub on_enable { | 
| 20 | 45 |  |  | 45 | 0 | 46 | my $code   = shift; | 
| 21 | 45 |  |  |  |  | 130 | my ($pkg)  = caller(2); | 
| 22 | 45 |  |  |  |  | 177 | my $routes = "${pkg}::__routes"; | 
| 23 |  |  |  |  |  |  | { | 
| 24 | 5 |  |  | 5 |  | 77 | no strict 'refs'; | 
|  | 5 |  |  |  |  | 6 |  | 
|  | 5 |  |  |  |  | 1436 |  | 
|  | 45 |  |  |  |  | 110 |  | 
| 25 | 45 |  | 100 |  |  | 211 | $$routes //= []; | 
| 26 | 45 |  |  |  |  | 167 | push @$$routes, $code; | 
| 27 |  |  |  |  |  |  | } | 
| 28 |  |  |  |  |  |  | } | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | sub _declare_route { | 
| 31 | 45 |  |  | 45 |  | 57 | my ( $http_verb, $path, $code ) = @_; | 
| 32 |  |  |  |  |  |  | on_enable( | 
| 33 |  |  |  |  |  |  | sub { | 
| 34 | 0 |  |  | 0 |  | 0 | my $self = shift; | 
| 35 | 0 |  |  |  |  | 0 | my $wrapped = sub { $self->serialisation->serialise( $code->(@_) ) }; | 
|  | 0 |  |  |  |  | 0 |  | 
| 36 |  |  |  |  |  |  | $self->framework->declare_route( | 
| 37 |  |  |  |  |  |  | $http_verb => $path => sub { | 
| 38 | 0 |  |  |  |  | 0 | perform_request( $wrapped, [ $self, $self->framework->request ] ); | 
| 39 |  |  |  |  |  |  | } | 
| 40 | 0 |  |  |  |  | 0 | ); | 
| 41 |  |  |  |  |  |  | } | 
| 42 | 45 |  |  |  |  | 142 | ); | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 0 |  |  | 0 | 0 | 0 | sub any     { _declare_route( any     => @_ ); } | 
| 46 | 15 |  |  | 15 | 0 | 40 | sub get     { _declare_route( get     => @_ ); } | 
| 47 | 30 |  |  | 30 | 0 | 51 | sub post    { _declare_route( post    => @_ ); } | 
| 48 | 0 |  |  | 0 | 0 |  | sub patch   { _declare_route( patch   => @_ ); } | 
| 49 | 0 |  |  | 0 | 0 |  | sub del     { _declare_route( del     => @_ ); } | 
| 50 | 0 |  |  | 0 | 0 |  | sub put     { _declare_route( put     => @_ ); } | 
| 51 | 0 |  |  | 0 | 0 |  | sub options { _declare_route( options => @_ ); } | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | sub perform_request { | 
| 54 | 0 |  |  | 0 | 0 |  | $_[0]->( @{ $_[1] } ); | 
|  | 0 |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | 1; |