File Coverage

blib/lib/Catalyst/Model/JSON/ViewData.pm
Criterion Covered Total %
statement 6 10 60.0
branch 0 2 0.0
condition n/a
subroutine 3 4 75.0
pod n/a
total 9 16 56.2


line stmt bran cond sub pod time code
1             package Catalyst::Model::JSON::ViewData;
2              
3 1     1   556 use Moo;
  1         1  
  1         5  
4            
5             extends 'Catalyst::Model';
6             with 'Catalyst::Component::InstancePerContext';
7             with 'Data::Perl::Role::Collection::Hash';
8            
9             sub build_per_context_instance {
10 4     4   361 my ($self, $c, %args) = @_;
11 4         66 return $self->new(%args);
12             }
13            
14 4     4   15 sub TO_JSON { +{shift->elements} }
15            
16             sub AUTOLOAD {
17 0     0     my ($self, @args) = @_;
18 0           my $key = our $AUTOLOAD;
19 0           $key =~ s/.*:://;
20 0 0         return scalar(@args) ?
21             $self->set($key, @args)
22             : $self->get($key);
23             }
24            
25             1;
26              
27             =head1 NAME
28              
29             Catalyst::Model::JSON::ViewData - Default model for Catalyst::View::JSON::PerRequest
30              
31             =head1 SYNOPSIS
32              
33             sub root :Chained(/) CaptureArgs(0) {
34             my ($self, $c) = @_;
35             $c->view->data->set(z=>1);
36             }
37              
38             =head1 DESCRIPTION
39              
40             This is the default model used by L<Catalyst::View::JSON::PerRequest> to
41             collect information that will be presented as JSON data to the client.
42              
43             Generally you will access this via '$c->view->data'. However it is setup as a
44             per request model in Catalyst so you can access it via '$c->model("JSON::ViewData")'.
45             which might have some use if you are populating values in other dependent models.
46              
47             =head1 METHODS
48              
49             This model consumes the role L<Data::Perl::Role::Collection::Hash> and gets
50             all its method from it.
51              
52             =head1 SEE ALSO
53              
54             L<Catalyst::View::JSON::PerRequest>, L<Catalyst>, L<Data::Perl>, L<Moo>.
55              
56             =head1 AUTHOR
57            
58             John Napiorkowski L<email:jjnapiork@cpan.org>
59            
60             =head1 COPYRIGHT & LICENSE
61            
62             Copyright 2015, John Napiorkowski L<email:jjnapiork@cpan.org>
63            
64             This library is free software; you can redistribute it and/or modify it under
65             the same terms as Perl itself.
66              
67             =cut