blib/lib/Yukki/Web/Response.pm

filter: Statementstmt 65.3% 34 / 52 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 64.7% 11 / 17 Podpod 100% 6 / 6 totaltotal 57.3% 51 / 89 SCAR 24.4
CC
7
Cov
55%
navigation_menu
20.0
add_navigation_items
20.0
navigation_menu_names
2.0
CRAP 11.5
« blib/lib/Yukki/Web/Plugin/Viewer.pm ↑ Summary blib/lib/Yukki/Model/User.pm »
1 package Yukki::Web::Response;
2 5 $Yukki::Web::Response::VERSION = '0.991_002'; # TRIAL
3  
4 5 ▶$Yukki::Web::Response::VERSION = '0.991002';use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use Type::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Types::Standard qw( Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Yukki::Types qw( BreadcrumbLinks NavigationMenuMap );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 ▶use Plack::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 5 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # ABSTRACT: the response to the client
17  
18  
19 5 has response => (
20 is => 'ro',
21 isa => class_type('Plack::Response'),
22 required => 1,
23 lazy => 1,
24 builder => '_build_response',
25 handles => [ qw(
26 status headers body header content_type content_length content_encoding
27 redirect location cookies finalize
28 ) ],
29 );
30  
31 sub _build_response {
32 1 ▶ my $self = shift;
Subroutine _build_response: called CC=1 SCAR=0.0
33 1 return Plack::Response->new(200, [ 'Content-type' => 'text/html; charset=utf-8' ]);
34 }
35  
36  
37 5 has page_title => (
38 is => 'rw',
39 isa => Str,
40 predicate => 'has_page_title',
41 );
42  
43  
44 has navigation => (
45 is => 'rw',
46 isa => NavigationMenuMap,
47 required => 1,
48 1 ▶ default => sub { +{} },
Subroutine __ANON__: called CC=1 SCAR=0.0
49 5 );
50  
51 sub navigation_menu_names {
52 0 ▶ my $self = shift;
Subroutine navigation_menu_names: not called CC=1 SCAR=6.9
Pod documented
53 0 keys $self->navigation->%*;
54 }
55  
56  
57 has breadcrumb => (
58 is => 'rw',
59 isa => BreadcrumbLinks,
60 required => 1,
61 1 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
62 5 );
63  
64 sub breadcrumb_links {
65 0 ▶ my $self = shift;
Subroutine breadcrumb_links: not called CC=1 SCAR=6.9
Pod documented
66 0 $self->breadcrumb->@*;
67 }
68  
69 sub has_breadcrumb {
70 0 ▶ my $self = shift;
Subroutine has_breadcrumb: not called CC=1 SCAR=6.9
Pod documented
71 0 scalar $self->breadcrumb->@*;
72 }
73  
74  
75 sub navigation_menu {
76 0 ▶ my ($self, $name) = @_;
Subroutine navigation_menu: not called CC=4 SCAR=30.0
Pod documented
77 0 ▶ return sort { ($a->{sort}//50) <=> ($b->{sort}//50) }
Condition0%0/4
$Yukki::Web::Response::a->{"sort"} // 50
l!l
00
$Yukki::Web::Response::b->{"sort"} // 50
l!l
00
MC/DC0%0/1
$Yukki::Web::Response::a->{"sort"} // 50
$Yukki::Web::Response::a->{"sort"}
MC/DC0%0/1
$Yukki::Web::Response::b->{"sort"} // 50
$Yukki::Web::Response::b->{"sort"}
Truth table0%0/2
A
A= $Yukki::Web::Response::a->{"sort"}
Aresult
11
00
Truth table0%0/2
A
A= $Yukki::Web::Response::b->{"sort"}
Aresult
11
00
78 0 ▶ @{ $self->navigation->{$name} // [] };
Condition0%0/2
$self->navigation->{$name} // []
l!l
00
MC/DC0%0/1
$self->navigation->{$name} // []
$self->navigation->{$name}
Truth table0%0/2
A
A= $self->navigation->{$name}
Aresult
11
00
79 }
80  
81  
82 0 ▶sub add_navigation_item { shift->add_navigation_items(@_) }
Subroutine add_navigation_item: not called CC=1 SCAR=6.9
Pod documented
83  
84 sub add_navigation_items {
85 0 ▶ my $self = shift;
Subroutine add_navigation_items: not called CC=4 SCAR=30.0
Pod documented
86 0 my $name_or_names = shift;
87  
88 0 ▶ my @names = ref $name_or_names ? @$name_or_names : ($name_or_names);
Branch: 1 branch
BranchTrueFalseTotal
ref $name_or_names ? : 0 0 0
89  
90 0 for my $name (@names) {
91 0 ▶ $self->navigation->{$name} //= [];
Condition0%0/2
$self->navigation->{$name} //= []
l!l
00
MC/DC0%0/1
$self->navigation->{$name} //= []
$self->navigation->{$name}
Truth table0%0/2
A
A= $self->navigation->{$name}
Aresult
11
00
92 0 push @{ $self->navigation->{$name} }, @_;
93 }
94 }
95  
96  
97 5 1;
98  
99 __END__
100  
101 =pod
102  
103 =encoding UTF-8
104  
105 =head1 NAME
106  
107 Yukki::Web::Response - the response to the client
108  
109 =head1 VERSION
110  
111 version 0.991_002
112  
113 =head1 DESCRIPTION
114  
115 An abstraction around the HTTP response that is astonishingly similar to L<Plack::Response>. Call C<finalize> to get the final PSGI response.
116  
117 =head1 ATTRIBUTES
118  
119 =head2 response
120  
121 This is the internal L<Plack::Response> object. Do not use.
122  
123 Use the delegated methods instead:
124  
125 status headers body header content_type content_length content_encoding
126 redirect location cookies finalize
127  
128 =head2 page_title
129  
130 This is the title to give the page in the HTML.
131  
132 =head2 navigation
133  
134 This is the navigation menu to place in the page. This is an array of hashes. Each entry should look like:
135  
136 {
137 label => 'Label',
138 href => '/link/to/somewhere',
139 sort => 50,
140 }
141  
142 A sorted list of items is retrieved using L</navigation_menu>. New items can be added with the L</add_navigation_item> and L</add_navigation_items> methods.
143  
144 =head2 breadcrumb
145  
146 This is the breadcrumb to display. It is an empty array by default (meaning no breadcrumb). Each element of the breadcrumb is formatted like navigation, except that C<sort> is not used here.
147  
148 =head1 METHODS
149  
150 =head2 navigation_menu
151  
152 my @items = $response->navigation_menu('repository');
153  
154 Returns a sorted list of navigation items for the named menu.
155  
156 =head2 add_navigation_item
157  
158 =head2 add_navigation_items
159  
160 $response->add_navigation_item(menu_name => {
161 label => 'Link Title',
162 url => '/path/to/some/place',
163 sort => 50,
164 });
165  
166 Add one or more items to the named menu. The first argument is always the name or names of the menu. Mutliple names may be given in an array reference. If multiple names are given, the menu items given will be added to each menu named. The remaining arguments are hash references that must have a C<label> and a C<url>. The C<sort> is optional.
167  
168 L</add_navigation_item> is a synonym for L</add_navigation_items>.
169  
170 =head2 breadcrumb_links
171  
172 Convenience accessor that returns C<breadcrumbs> as a list.
173  
174 =head2 has_breadcrumb
175  
176 Returns a true value if C<breadcrumbs> has any items in it.
177  
178 =head2 has_page_title
179  
180 Returns a true value if C<page_title> is set.
181  
182 =head2 navigation_menu_names
183  
184 Convenience accessor that returns C<navigation> as a list.
185  
186 =head1 AUTHOR
187  
188 Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
189  
190 =head1 COPYRIGHT AND LICENSE
191  
192 This software is copyright (c) 2017 by Qubling Software LLC.
193  
194 This is free software; you can redistribute it and/or modify it under
195 the same terms as the Perl 5 programming language system itself.
196  
197 =cut
« blib/lib/Yukki/Web/Plugin/Viewer.pm ↑ Summary blib/lib/Yukki/Model/User.pm »