blib/lib/Plack/App/Search.pm

filter: Statementstmt 97.5% 39 / 40 Branchbran 83.3% 20 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 93.1% 68 / 73 CC 13 SCAR 14.0
CC
13
Cov
92%
__ANON__
5.7
_css
5.1
_prepare_app
5.0
CRAP 4.0
↑ Summary
1 package Plack::App::Search;
2  
3 3 ▶use base qw(Plack::Component::Tags::HTML);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Plack::Util::Accessor qw(generator image_height image_link image_radius
Subroutine BEGIN: called CC=1 SCAR=0.0
8 search_method search_placeholder search_title search_url tags_after
9 3 title);
10 3 ▶use Tags::HTML::Container;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 our $VERSION = 0.05;
13  
14 5 ▶sub _prepare_app {
Subroutine _prepare_app: called CC=5 SCAR=16.1
15 5 my $self = shift;
16  
17 # Defaults which rewrite defaults in module which I am inheriting.
18 5 ▶ if (! $self->generator) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->generator) 2 3 5
19 2 $self->generator(__PACKAGE__.'; Version: '.$VERSION);
20 }
21  
22 5 ▶ if (! $self->title) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->title) 2 3 5
23 2 $self->title('Search page');
24 }
25  
26 # Inherite defaults.
27 5 $self->SUPER::_prepare_app;
28  
29 # Defaults from this module.
30 5 ▶ if (! $self->search_method) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->search_method) 4 1 5
31 4 $self->search_method('get');
32 }
33  
34 5 ▶ if (! $self->search_url) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->search_url) 2 3 5
35 2 $self->search_url('https://env.skim.cz');
36 }
37  
38 5 $self->{'_container'} = Tags::HTML::Container->new(
39 'css' => $self->css,
40 'css_inner' => 'search',
41 'tags' => $self->tags,
42 );
43  
44 5 return;
45 }
46  
47 5 ▶sub _css {
Subroutine _css: called CC=5 SCAR=16.2
48 5 my $self = shift;
49  
50 5 $self->{'_container'}->process_css;
51 5 ▶ if (defined $self->image_link) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->image_link) 1 4 5
52 1 ▶ $self->css->put(
Branch: 2 branches
BranchTrueFalseTotal
defined $self->image_radius ? : 0 1 1
defined $self->image_height ? : 0 1 1
53 ['s', '.search'],
54 ['d', 'display', 'flex'],
55 ['d', 'flex-direction', 'column'],
56 ['d', 'align-items', 'center'],
57 ['e'],
58  
59 ['s', '.search img'],
60 ['d', 'margin-bottom', '20px'],
61 ['d', 'margin-left', 'auto'],
62 ['d', 'margin-right', 'auto'],
63 defined $self->image_radius ? (
64 ['d', 'border-radius', $self->image_radius],
65 ) : (),
66 defined $self->image_height ? (
67 ['d', 'height', $self->image_height],
68 ) : (),
69 ['e'],
70 );
71 }
72 $self->css->put(
73 5 ▶ ['s', '.search form'],
Branch: 1 branch
BranchTrueFalseTotal
!defined($self->search_title) ? : 3 2 5
74 ['d', 'display', 'flex'],
75 ['d', 'align-items', 'center'],
76 ['e'],
77  
78 ['s', '.search input[type="text"]'],
79 ['d', 'padding', '10px'],
80 ['d', 'border-radius', '4px'],
81 ['d', 'border', '1px solid #ccc'],
82 ['e'],
83  
84 ['s', '.search button'],
85 ['d', 'margin-left', '10px'],
86 ['d', 'padding', '10px 20px'],
87 ['d', 'border-radius', '4px'],
88 ['d', 'background-color', '#4CAF50'],
89 ['d', 'color', 'white'],
90 ['d', 'border', 'none'],
91 ['d', 'cursor', 'pointer'],
92 ! defined $self->search_title ? (
93 ['d', 'display', 'none'],
94 ) : (),
95 ['e'],
96  
97 ['s', '.search button:hover'],
98 ['d', 'background-color', '#45a049'],
99 ['e'],
100 );
101  
102 5 return;
103 }
104  
105 5 ▶sub _tags_middle {
Subroutine _tags_middle: called CC=1 SCAR=0.1
106 5 my $self = shift;
107  
108 $self->{'_container'}->process(
109 5 ▶ sub {
Subroutine __ANON__: called CC=5 SCAR=17.4
110 $self->tags->put(
111 $self->image_link ? (
112 ['b', 'img'],
113 ['a', 'src', $self->image_link],
114 ['e', 'img'],
115 ) : (),
116 ['b', 'form'],
117 ['a', 'method', $self->search_method],
118 ['a', 'action', $self->search_url],
119 ['b', 'input'],
120 ['a', 'type', 'text'],
121 ['a', 'autofocus', 'autofocus'],
122 defined $self->search_placeholder ? (
123 ['a', 'placeholder', $self->search_placeholder],
124 ) : (),
125 ['a', 'name', 'search'],
126 ['e', 'input'],
127 ['b', 'button'],
128 ['a', 'type', 'submit'],
129 defined $self->search_title ? (
130 ['d', $self->search_title],
131 ) : (),
132 ['e', 'button'],
133 ['e', 'form'],
134  
135 defined $self->tags_after ? (
136 0 ▶ @{$self->tags_after},
Branch: 4 branches
BranchTrueFalseTotal
$self->image_link ? : 1 4 5
defined $self->search_placeholder ? : 0 5 5
defined $self->search_title ? : 2 3 5
defined $self->tags_after ? : 0 5 5
137 ) : (),
138 );
139 },
140 5 );
141  
142 5 return;
143 }
144  
145 3 1;
146  
147 __END__
↑ Summary