blib/lib/Yukki/Web/Response.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 61 CC 2 SCAR 11.0
CC
2
Cov
0%
add_navigation_items
6.0
_build_response
2.0
navigation_menu
2.0
CRAP 3.0
1 package Yukki::Web::Response;
2 {
3 $Yukki::Web::Response::VERSION = '0.140290';
4 }
5 use Moose;
6  
7 use Yukki::Types qw( BreadcrumbLinks NavigationMenuMap );
8  
9 use Plack::Response;
10  
11 # ABSTRACT: the response to the client
12  
13  
14 has response => (
15 is => 'ro',
16 isa => 'Plack::Response',
17 required => 1,
18 lazy_build => 1,
19 handles => [ qw(
20 status headers body header content_type content_length content_encoding
21 redirect location cookies finalize
22 ) ],
23 );
24  
25 sub _build_response {
26 my $self = shift;
27 return Plack::Response->new(200, [ 'Content-type' => 'text/html; charset=utf-8' ]);
28 }
29  
30  
31 has page_title => (
32 is => 'rw',
33 isa => 'Str',
34 predicate => 'has_page_title',
35 );
36  
37  
38 has navigation => (
39 is => 'rw',
40 isa => NavigationMenuMap,
41 required => 1,
42 default => sub { +{} },
43 traits => [ 'Hash' ],
44 handles => {
45 navigation_menu_names => 'keys',
46 },
47 );
48  
49  
50 has breadcrumb => (
51 is => 'rw',
52 isa => BreadcrumbLinks,
53 required => 1,
54 default => sub { [] },
55 traits => [ 'Array' ],
56 handles => {
57 breadcrumb_links => 'elements',
58 },
59 );
60  
61  
62 sub navigation_menu {
63 my ($self, $name) = @_;
64 return sort { ($a->{sort}//50) <=> ($b->{sort}//50) }
65 @{ $self->navigation->{$name} // [] };
66 }
67  
68  
69 sub add_navigation_item { shift->add_navigation_items(@_) }
70  
71 sub add_navigation_items {
72 my $self = shift;
73 my $name_or_names = shift;
74  
75 my @names = ref $name_or_names ? @$name_or_names : ($name_or_names);
76  
77 for my $name (@names) {
78 $self->navigation->{$name} //= [];
79 push @{ $self->navigation->{$name} }, @_;
80 }
81 }
82  
83 1;
84  
85 __END__