File Coverage

blib/lib/Articulate/Request.pm
Criterion Covered Total %
statement 16 17 94.1
branch n/a
condition n/a
subroutine 6 7 85.7
pod 2 2 100.0
total 24 26 92.3


line stmt bran cond sub pod time code
1             package Articulate::Request;
2 10     10   46 use strict;
  10         15  
  10         346  
3 10     10   43 use warnings;
  10         13  
  10         247  
4              
5 10     10   39 use Moo;
  10         16  
  10         46  
6 10     10   4392 use Articulate::Service;
  10         24  
  10         162  
7              
8             =head1 NAME
9              
10             Articulate::Request - represent a request
11              
12             =cut
13              
14             =head1 FUNCTIONS
15              
16             =head3 articulate_request
17              
18             my $request = articulate_request verb => $data;
19              
20             Creates a new request, using the verb and data supplied as the respective arguments.
21              
22             =cut
23              
24 10     10   2074 use Exporter::Declare;
  10         17  
  10         63  
25             default_exports qw(articulate_request);
26              
27             sub articulate_request {
28 4     4 1 2436 __PACKAGE__->new(
29             {
30             verb => shift,
31             data => shift
32             }
33             );
34             }
35              
36             =head1 METHODS
37              
38             =head3 new
39              
40             An unremarkable Moo constructor.
41              
42             =cut
43              
44             =head3 perform
45              
46             Sends the to the articulate service.
47              
48             Note: the behaviour of this method may change!
49              
50             =cut
51              
52             sub perform {
53 0     0 1   service->process_request(shift);
54             }
55              
56             =head1 ATTRIBUTES
57              
58             =head3 verb
59              
60             The action being performed, e.g. C, C, etc. The verbs available are entirely dependant on the application: A request will be handled by a service provider (see Articulate::Service) which will typically decide if it can fulfil the request based on the verb.
61              
62             =cut
63              
64             has verb => (
65             is => 'rw',
66             default => sub { 'error' }
67             );
68              
69             =head3 data
70              
71             The information passed along with the request, e.g. C<< { location => '/zone/public/article/hello-world' } >>. This should always be a hashref.
72              
73             =cut
74              
75             has data => (
76             is => 'rw',
77             default => sub { {} }
78             );
79              
80             =head3 app
81              
82             The app for which the request has been made.
83              
84             =cut
85              
86             has app => (
87             is => 'rw',
88             weak_ref => 1,
89             );
90              
91             =head3 user_id
92              
93             The user_id making the request. This is typically inferred from the framework.
94              
95             =cut
96              
97             has user_id => (
98             is => 'rw',
99             lazy => 1,
100             default => sub {
101             my $self = shift;
102             return undef unless $self->app;
103             return undef unless $self->app->components->{framework};
104             return $self->app->components->{framework}->user_id;
105             }
106             );
107              
108             1;