DBIC/Resource/HAL/Role/Root.pm

filter: Statementstmt 97.5% 39 / 40 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 92.4% 49 / 53 CC 6 SCAR 13.9
CC
6
Cov
96%
render_api_as_hal
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.0
« DBIC/Resource/ActiveModel/Role/DBIC.pm ↑ Summary DBIC/RouteMaker.pm »
1 package WebAPI::DBIC::Resource::HAL::Role::Root;
2 25 $WebAPI::DBIC::Resource::HAL::Role::Root::VERSION = '0.004002';
3  
4 25 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 25 ▶use JSON::MaybeXS qw(JSON);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 25 requires '_build_content_types_provided';
9 25 requires 'encode_json';
10  
11  
12 4 ▶around '_build_content_types_provided' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
13 4 my $orig = shift;
14 4 my $self = shift;
15 4 my $types = $self->$orig();
16 4 unshift @$types, { 'application/hal+json' => 'to_json_as_hal' };
17 4 return $types;
18 25 };
19  
20  
21 1 ▶sub to_json_as_hal { return $_[0]->encode_json($_[0]->render_api_as_hal()) }
Subroutine to_json_as_hal: called CC=1 SCAR=0.0
Pod undocumented
22  
23  
24 1 ▶sub render_api_as_hal {
Subroutine render_api_as_hal: called CC=6 SCAR=17.9
Pod undocumented
25 1 my $self = shift;
26  
27 1 my $request = $self->request;
28 1 my $router = $self->router;
29 1 my $path = $request->env->{REQUEST_URI}; # "/clients/v1/";
30  
31 # we get here when the HAL Browser requests the root JSON
32 1 my %links = (self => { href => $path } );
33 1 foreach my $route (@{$router->routes}) {
34 23 my @parts;
35 my %attr;
36  
37 23 for my $c (@{ $route->components }) {
38 39 ▶ if ($route->is_component_variable($c)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($route->is_component_variable($c)) { } 15 24 39
39 15 my $name = $route->get_component_name($c);
40 15 push @parts, "{/$name}";
41 15 $attr{templated} = JSON->true;
42 } else {
43 24 push @parts, "$c";
44 }
45 }
46 23 ▶ next unless @parts;
Branch: 1 branch
BranchTrueFalseTotal
unless @parts 1 22 23
47  
48 22 my $title;
49 22 ▶ if (exists $route->defaults->{result_class}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $route->defaults->{'result_class'}) { } 22 0 22
50 22 $title = join(" ", (split /::/, $route->defaults->{result_class})[-3,-1]);
51 } else {
52 0 ($title) = split( /\?/, $route->path);
53 }
54  
55 22 my $url = $path . join("", @parts);
56 22 $links{join("", @parts)} = {
57 href => $url,
58 title => $title,
59 %attr
60 };
61 }
62  
63 1 return { _links => \%links, };
64 }
65  
66  
67 25 1;
68  
69 __END__
« DBIC/Resource/ActiveModel/Role/DBIC.pm ↑ Summary DBIC/RouteMaker.pm »