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