| 1 | package WebAPI::DBIC::Resource::Role::Item; | ||
| 2 | 25 | $WebAPI::DBIC::Resource::Role::Item::VERSION = '0.004002'; | |
| 3 | |||
| 4 | 25 | ▶ | use Moo::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | |||
| 7 | 25 | requires 'render_item_as_plain_hash'; | |
| 8 | 25 | requires 'id_unique_constraint_name'; | |
| 9 | 25 | requires 'encode_json'; | |
| 10 | 25 | requires 'set'; | |
| 11 | |||
| 12 | |||
| 13 | 25 | has id => ( # array of 1 or more key values from url path | |
| 14 | is => 'ro', | ||
| 15 | #isa => array ref | ||
| 16 | lazy => 1, | ||
| 17 | builder => '_build_id' | ||
| 18 | ); | ||
| 19 | |||
| 20 | 0 | ▶ | sub _build_id { |
|
Subroutine
_build_id: not called CC=1 SCAR=6.9
| |||
| 21 | # we could possibly try to extract an id from item() if that's set | ||
| 22 | # (but we'd need to avoid infinite recursion) | ||
| 23 | 0 | die sprintf "No id provided for %s", ref shift; | |
| 24 | } | ||
| 25 | |||
| 26 | 25 | has item => ( | |
| 27 | is => 'rw', # XXX | ||
| 28 | lazy => 1, | ||
| 29 | builder => '_build_item' | ||
| 30 | ); | ||
| 31 | |||
| 32 | 72 | ▶ | sub _build_item { |
|
Subroutine
_build_item: called CC=1 SCAR=0.0
| |||
| 33 | 72 | my $self = shift; | |
| 34 | 72 | return $self->set->find( @{ $self->id }, { key => $self->id_unique_constraint_name } ); | |
| 35 | } | ||
| 36 | |||
| 37 | 25 | has content_types_provided => ( | |
| 38 | is => 'lazy', | ||
| 39 | ); | ||
| 40 | |||
| 41 | 72 | ▶ | sub _build_content_types_provided { |
|
Subroutine
_build_content_types_provided: called CC=1 SCAR=0.0
| |||
| 42 | 72 | return [ { 'application/vnd.wapid+json' => 'to_json_as_plain' } ] | |
| 43 | } | ||
| 44 | |||
| 45 | 25 | ▶ | sub to_json_as_plain { return $_[0]->encode_json($_[0]->render_item_as_plain_hash($_[0]->item)) } |
|
Subroutine
to_json_as_plain: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 46 | |||
| 47 | 72 | ▶ | sub resource_exists { return !! $_[0]->item } |
|
Subroutine
resource_exists: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 48 | |||
| 49 | 70 | ▶ | sub allowed_methods { return [ qw(GET HEAD) ] } |
|
Subroutine
allowed_methods: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 50 | |||
| 51 | |||
| 52 | 25 | 1; | |
| 53 | |||
| 54 | __END__ | ||