| 1 | package Articulate::Request; | ||||||||||
| 2 | 11 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 11 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 11 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 11 | ▶ | use Articulate::Service; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | ▶ | use Exporter::Declare; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 11 | default_exports qw(new_request); | |||||||||
| 27 | |||||||||||
| 28 | 4 | ▶ | sub new_request { | ||||||||
|
Subroutine
new_request: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 29 | 4 | __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 | 0 | ▶ | sub perform { | ||||||||
|
Subroutine
perform: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 54 | 0 | service->process_request(shift); | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | =head1 ATTRIBUTES | ||||||||||
| 58 | |||||||||||
| 59 | =head3 verb | ||||||||||
| 60 | |||||||||||
| 61 | The action being performed, e.g. C<create>, C<read>, 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 | 0 | ▶ | default => sub { 'error' } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 71 | 11 | ); | |||||||||
| 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 | 0 | ▶ | default => sub { {} } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 84 | 11 | ); | |||||||||
| 85 | |||||||||||
| 86 | =head3 app | ||||||||||
| 87 | |||||||||||
| 88 | The app for which the request has been made. | ||||||||||
| 89 | |||||||||||
| 90 | =cut | ||||||||||
| 91 | |||||||||||
| 92 | 11 | 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 | 4 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=16.5
| |||||||||||
| 108 | 4 | my $self = shift; | |||||||||
| 109 | 4 | ▶ | return undef unless $self->app; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 110 | 0 | ▶ | return undef unless $self->app->components->{framework}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 111 | 0 | return $self->app->components->{framework}->user_id; | |||||||||
| 112 | } | ||||||||||
| 113 | 11 | ); | |||||||||
| 114 | |||||||||||
| 115 | 11 | 1; | |||||||||