File Coverage

blib/lib/WebAPI/DBIC/Resource/Role/Item.pm
Criterion Covered Total %
statement 3 11 27.2
branch n/a
condition n/a
subroutine 1 7 14.2
pod 0 3 0.0
total 4 21 19.0


line stmt bran cond sub pod time code
1             package WebAPI::DBIC::Resource::Role::Item;
2             $WebAPI::DBIC::Resource::Role::Item::VERSION = '0.003002';
3              
4 2     2   16120481 use Moo::Role;
  2         60182  
  2         16  
5              
6              
7             requires 'render_item_as_plain_hash';
8             requires 'id_unique_constraint_name';
9             requires 'encode_json';
10             requires 'set';
11              
12              
13             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             sub _build_id {
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     0     die sprintf "No id provided for %s", ref shift;
24             }
25              
26             has item => (
27             is => 'rw', # XXX
28             lazy => 1,
29             builder => '_build_item'
30             );
31              
32             sub _build_item {
33 0     0     my $self = shift;
34 0           return $self->set->find( @{ $self->id }, { key => $self->id_unique_constraint_name } );
  0            
35             }
36              
37             has content_types_provided => (
38             is => 'lazy',
39             );
40              
41             sub _build_content_types_provided {
42 0     0     return [ { 'application/json' => 'to_json_as_plain' } ]
43             }
44              
45 0     0 0   sub to_json_as_plain { return $_[0]->encode_json($_[0]->render_item_as_plain_hash($_[0]->item)) }
46              
47 0     0 0   sub resource_exists { return !! $_[0]->item }
48              
49 0     0 0   sub allowed_methods { return [ qw(GET HEAD) ] }
50              
51              
52             1;
53              
54             __END__
55              
56             =pod
57              
58             =encoding UTF-8
59              
60             =head1 NAME
61              
62             WebAPI::DBIC::Resource::Role::Item
63              
64             =head1 VERSION
65              
66             version 0.003002
67              
68             =head1 DESCRIPTION
69              
70             Handles GET and HEAD requests for requests representing individual resources,
71             e.g. a single row of a database table.
72              
73             Supports the C<application/json> content types.
74              
75             =head1 NAME
76              
77             WebAPI::DBIC::Resource::Role::Item - methods related to handling requests for item resources
78              
79             =head1 AUTHOR
80              
81             Tim Bunce <Tim.Bunce@pobox.com>
82              
83             =head1 COPYRIGHT AND LICENSE
84              
85             This software is copyright (c) 2015 by Tim Bunce.
86              
87             This is free software; you can redistribute it and/or modify it under
88             the same terms as the Perl 5 programming language system itself.
89              
90             =cut