| 1 | package Magpie::Resource; | ||||||||||||||||||||
| 2 | 48 | $Magpie::Resource::VERSION = '1.141660'; | |||||||||||||||||||
| 3 | # ABSTRACT: Abstract base class for all resource types; | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 48 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 48 | extends 'Magpie::Component'; | |||||||||||||||||||
| 7 | 48 | with 'Magpie::Dispatcher::RequestMethod'; | |||||||||||||||||||
| 8 | 48 | ▶ | use Magpie::Constants; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 48 | __PACKAGE__->register_events(Magpie::Dispatcher::RequestMethod::events()); | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 48 | has '+_trait_namespace' => ( default => 'Magpie::Plugin::Resource' ); | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 48 | has produces => ( | |||||||||||||||||||
| 15 | is => 'ro', | ||||||||||||||||||||
| 16 | isa => 'Str', | ||||||||||||||||||||
| 17 | required => 1, | ||||||||||||||||||||
| 18 | default => 'text/plain', | ||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 48 | has consumes => ( | |||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||
| 23 | isa => 'Str', | ||||||||||||||||||||
| 24 | required => 1, | ||||||||||||||||||||
| 25 | default => 'text/plain', | ||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 48 | has data => ( | |||||||||||||||||||
| 29 | is => 'rw', | ||||||||||||||||||||
| 30 | predicate => 'has_data', | ||||||||||||||||||||
| 31 | clearer => 'clear_data', | ||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 48 | has state => ( | |||||||||||||||||||
| 35 | is => 'rw', | ||||||||||||||||||||
| 36 | isa => 'Str', | ||||||||||||||||||||
| 37 | default => 'uninitialized', | ||||||||||||||||||||
| 38 | required => 1, | ||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | has dependencies => ( | ||||||||||||||||||||
| 42 | traits => ['Hash'], | ||||||||||||||||||||
| 43 | is => 'rw', | ||||||||||||||||||||
| 44 | isa => 'HashRef[HashRef]', | ||||||||||||||||||||
| 45 | 118 | ▶ | default => sub { {} }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 46 | 48 | handles => { | |||||||||||||||||||
| 47 | add_dependency => 'set', | ||||||||||||||||||||
| 48 | get_dependency => 'get', | ||||||||||||||||||||
| 49 | delete_dependency => 'delete', | ||||||||||||||||||||
| 50 | has_dependencies => 'count', | ||||||||||||||||||||
| 51 | }, | ||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | sub methods_implemented { | ||||||||||||||||||||
| 55 | 2 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
methods_implemented: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||
| 56 | 2 | my %implemented = (); | |||||||||||||||||||
| 57 | 2 | foreach my $class ( $self->meta->linearized_isa ) { | |||||||||||||||||||
| 58 | 8 | ▶ | next if $class =~ /^(Magpie|Moose)::/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | 1 | foreach (HTTP_METHODS){ | |||||||||||||||||||
| 60 | 9 | ▶ | $implemented{$_}++ if $class->meta->has_method($_); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | 2 | return ( keys( %implemented )); | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | sub method_not_allowed { | ||||||||||||||||||||
| 67 | 2 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
method_not_allowed: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 68 | 2 | ▶ | my $method = $self->plack_request->method || 'unknown'; | ||||||||||||||||||
|
Condition100%2/2
$self->plack_request->method || 'unknown'
MC/DC100%1/1
$self->plack_request->method || 'unknown'
$self->plack_request->method
Truth table100%2/2
A
A= $self->plack_request->method
| |||||||||||||||||||||
| 69 | 2 | my @allowed = $self->methods_implemented; | |||||||||||||||||||
| 70 | 2 | $self->set_error( | |||||||||||||||||||
| 71 | { status_code => 405, | ||||||||||||||||||||
| 72 | reason => "Method '$method' not allowed.", | ||||||||||||||||||||
| 73 | additional_headers => [ Allow => \@allowed ], | ||||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||
| 76 | 2 | return DONE; | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | sub GET { | ||||||||||||||||||||
| 80 | 1 | ▶ | shift->method_not_allowed(@_); | ||||||||||||||||||
|
Subroutine
GET: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | sub POST { | ||||||||||||||||||||
| 84 | 0 | ▶ | shift->method_not_allowed(@_); | ||||||||||||||||||
|
Subroutine
POST: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | sub PUT { | ||||||||||||||||||||
| 88 | 0 | ▶ | shift->method_not_allowed(@_); | ||||||||||||||||||
|
Subroutine
PUT: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | sub DELETE { | ||||||||||||||||||||
| 92 | 0 | ▶ | shift->method_not_allowed(@_); | ||||||||||||||||||
|
Subroutine
DELETE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | sub HEAD { | ||||||||||||||||||||
| 96 | 0 | ▶ | shift->method_not_allowed(@_); | ||||||||||||||||||
|
Subroutine
HEAD: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | sub OPTIONS { | ||||||||||||||||||||
| 100 | 0 | ▶ | shift->method_not_allowed(@_); | ||||||||||||||||||
|
Subroutine
OPTIONS: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 101 | } | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | sub TRACE { | ||||||||||||||||||||
| 104 | 0 | ▶ | shift->method_not_allowed(@_); | ||||||||||||||||||
|
Subroutine
TRACE: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | sub PATCH { | ||||||||||||||||||||
| 108 | 0 | ▶ | shift->method_not_allowed(@_); | ||||||||||||||||||
|
Subroutine
PATCH: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 109 | } | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | sub CONNECT { | ||||||||||||||||||||
| 112 | 0 | ▶ | shift->method_not_allowed(@_); | ||||||||||||||||||
|
Subroutine
CONNECT: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | # convenience for container-based Resources | ||||||||||||||||||||
| 116 | sub get_entity_id { | ||||||||||||||||||||
| 117 | 3 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
get_entity_id: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||
| 118 | 3 | my $path = $self->request->path_info; | |||||||||||||||||||
| 119 | 3 | ▶ | return undef if $path =~ /\/$/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 120 | 3 | my @steps = split '/', $path; | |||||||||||||||||||
| 121 | 3 | ▶ | my $id = $self->request->param('id') || pop @steps; | ||||||||||||||||||
|
Condition33%1/3
$self->request->param('id') || pop @steps
MC/DC0%0/2
$self->request->param('id') || pop @steps
$self->request->param('id')
pop @steps
Truth table33%1/3
A || B
A= $self->request->param('id')B= pop @steps
| |||||||||||||||||||||
| 122 | 3 | return $id; | |||||||||||||||||||
| 123 | } | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 48 | 1; | |||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | =pod | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | =head1 NAME | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | Magpie::Resource - Abstract base class for all resource types; | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | =head1 VERSION | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | version 1.141660 | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | =head1 DESCRIPTION | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | A resource is not the thing that is transferred across the wire or picked | ||||||||||||||||||||
| 142 | up off the disk or seen from afar while walking your dog. Each of those is | ||||||||||||||||||||
| 143 | only a representation. The same is true of physical objects encountered in | ||||||||||||||||||||
| 144 | life and never identified with URI and never made accessible on the net. | ||||||||||||||||||||
| 145 | Yes, it does present a bit of a quandary, but it is one that we have all | ||||||||||||||||||||
| 146 | learned to live with. Our eyes are not powerful enough to see identity | ||||||||||||||||||||
| 147 | through the representations, but our minds are powerful enough to associate | ||||||||||||||||||||
| 148 | identity to that which we see. Do I think of a different identifier every | ||||||||||||||||||||
| 149 | time I see my dog, or do I simply think of my dog as one identity and | ||||||||||||||||||||
| 150 | experience many representations of that identity over time (and on into | ||||||||||||||||||||
| 151 | memory and imagination)? | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | Roy Fielding - July 2002 | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | =head1 AUTHORS | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | =over 4 | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | =item * | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | Kip Hampton <kip.hampton@tamarou.com> | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | =item * | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | Chris Prather <chris.prather@tamarou.com> | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | =back | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | This software is copyright (c) 2011 by Tamarou, LLC. | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 174 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | =head1 SEE ALSO | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | =over 4 | ||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | =item * | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | L<Magpie> | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | =back | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | =cut | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | __END__ | ||||||||||||||||||||
| 190 | |||||||||||||||||||||