XTaTIK/Controller/Root.pm

filter: Statementstmt 21.1% 11 / 52 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 33.3% 3 / 9 Podpod 0.0% 0 / 6 totaltotal 15.3% 14 / 91 CC 15 SCAR 29.3
CC
15
Cov
15%
products_category
42.0
product
20.0
contact_post
12.0
CRAP 18.7
« XTaTIK/Model/Blog.pm ↑ Summary XTaTIK/Common.pm »
1 package XTaTIK::Controller::Root;
2  
3 1 our $VERSION = '0.005003'; # VERSION
4  
5 1 ▶use Mojo::Base 'Mojolicious::Controller';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use XTaTIK::Common qw/n_to_br set_product_pic/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use experimental 'postderef';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 0 ▶sub index {
Subroutine index: not called CC=2 SCAR=17.9
Pod undocumented
10 0 my $self = shift;
11  
12 0 my @products = $self->products->get_by_number(
13 split /\n/, $self->xvar('hot_products')
14 );
15  
16 0 set_product_pic( $self, @$_{qw/image number/} ) for @products;
17 0 $self->stash( hot_products => \@products, );
18 }
19  
20 0 ▶sub products_category {
Subroutine products_category: not called CC=6 SCAR=37.4
Pod undocumented
21 0 my $self = shift;
22  
23 0 my ( $products, $return_path, $return_name )
24 = $self->products->get_category( $self->stash('category') );
25  
26 0 ▶ @$products or $self->reply->not_found;
Branch: 1 branch
BranchTrueFalseTotal
@$products or $self->reply->not_found 0 0 0
27  
28 0 for ( @$products ) {
29 0 set_product_pic( $self, @$_{qw/image number/} ) for
30 grep exists $_->{number}, $_->{contents}->@*;
31 }
32  
33 0 my $title = $self->stash('category') =~ s{^\s*/\s*}{}r;
34 0 ▶ $title = $self->xtext('products_nav_name') unless length $title;
Branch: 1 branch
BranchTrueFalseTotal
unless length $title 0 0 0
35 0 ▶ $title = join '/', (split m{\s*/\s*}, $title )[-2,-1]
Branch: 1 branch
BranchTrueFalseTotal
if $title =~ tr[/][] > 1 0 0 0
36 if $title =~ tr{/}{} > 1;
37  
38 0 $title =~ s{/}{ / }g;
39  
40 0 my $meta_desc = join ', ', reverse $self->xtext('market'),
41 split m{\s*/\s*}, $title;
42  
43 0 $self->stash(
44 products => $products,
45 return_path => $return_path,
46 return_name => $return_name,
47 page_title => $title,
48 meta_desc => $meta_desc,
49 );
50 }
51  
52 0 ▶sub product {
Subroutine product: not called CC=4 SCAR=30.0
Pod undocumented
53 0 my $self = shift;
54 0 my ( $product ) = $self->products->get_by_url( $self->stash('url') );
55 0 ▶ $product or $self->reply->not_found;
Branch: 1 branch
BranchTrueFalseTotal
$product or $self->reply->not_found 0 0 0
56  
57 0 set_product_pic( $self, @$product{qw/image number/} );
58  
59 0 my $desc = Mojo::DOM->new( $product->{description} )->all_text;
60 $desc = "$product->{group_desc}; $desc"
61 0 ▶ if length $product->{group_desc};
Branch: 1 branch
BranchTrueFalseTotal
if length $product->{"group_desc"} 0 0 0
62  
63 0 ▶ $desc = substr($desc, 0, 152) . '...'
Branch: 1 branch
BranchTrueFalseTotal
if length $desc > 155 0 0 0
64 if length $desc > 155;
65  
66 0 $self->stash(
67 product => $product,
68 meta_desc => $desc,
69 );
70 };
71  
72 0 ▶sub contact_post {
Subroutine contact_post: not called CC=3 SCAR=24.8
Pod undocumented
73 0 my $self = shift;
74  
75 0 $self->form_checker(
76 rules => {
77 name => { max => 200, },
78 email => { max => 200, },
79 province => {
80 valid_values => [
81 qw/AB BC MB NB NF NT NS NU ON PE QC SK YT/
82 ],
83 valid_values_error => 'Please choose your province',
84 },
85 message => { max => 100_000 },
86 },
87 );
88  
89 0 ▶ return $self->render( template => 'root/contact' )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->form_checker_ok 0 0 0
90 unless $self->form_checker_ok;
91  
92 # Check CSRF token
93 0 ▶ return $self->render(text => 'Bad CSRF token!', status => 403)
Branch: 1 branch
BranchTrueFalseTotal
if $self->validation->csrf_protect->has_error("csrf_token") 0 0 0
94 if $self->validation->csrf_protect->has_error('csrf_token');
95  
96 0 $self->stash( visitor_ip => $self->tx->remote_address );
97 0 $self->stash( message => n_to_br( $self->param('message')) );
98  
99 $self->mail(
100 test => $self->config('mail')->{test},
101 to => $self->config('mail')->{to}{quicknote},
102 from => $self->config('mail')->{from}{quicknote},
103 subject => 'Quicknote from '
104 . $self->config('text')->{website_domain},
105  
106 0 type => 'text/html',
107 data => $self->render_to_string('email-templates/quicknote'),
108 );
109  
110 0 return $self->render( template => 'root/contact' );
111 }
112  
113 0 ▶sub feedback_post {
Subroutine feedback_post: not called CC=2 SCAR=17.9
Pod undocumented
114 0 my $self = shift;
115  
116 0 $self->form_checker(
117 rules => {
118 email => { max => 200, optional => 1, },
119 feedback => { max => 100_000, },
120 },
121 );
122  
123 0 ▶ return $self->render( template => 'root/feedback' )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->form_checker_ok 0 0 0
124 unless $self->form_checker_ok;
125  
126 0 $self->stash(
127 visitor_ip => $self->tx->remote_address,
128 feedback => n_to_br( $self->param('feedback') ),
129 );
130  
131 $self->mail(
132 test => $self->config('mail')->{test},
133 to => $self->config('mail')->{to}{feedback},
134 from => $self->config('mail')->{from}{feedback},
135 subject => 'Site Feedback from '
136 . $self->config('text')->{website_domain},
137  
138 0 type => 'text/html',
139 data => $self->render_to_string('email-templates/feedback'),
140 );
141  
142 0 return $self->render( template => 'root/feedback' );
143 }
144  
145 0 ▶sub sitemap {
Subroutine sitemap: not called CC=3 SCAR=24.8
Pod undocumented
146 0 my $self = shift;
147  
148 $self->stash(
149 urls => [
150 map +{
151 freq => 'weekly',
152 priority => '0.9',
153 url => $self->xtext('website_proto')
154 . '://'
155 . $self->xtext('website_domain')
156 . $_,
157 }, qw{
158 /
159 /blog
160 /history
161 /about
162 /contact
163 },
164 0 ▶ ( map '/blog/' . $_->{url}, @{$self->blog->brief_list ||[]}),
Condition0%0/2
$self->blog->brief_list || []
l!l
00
MC/DC0%0/1
$self->blog->brief_list || []
$self->blog->brief_list
Truth table0%0/2
A
A= $self->blog->brief_list
Aresult
11
00
165 0 ▶ map '/product/' . $_->{url}, @{ $self->products->get_all||[] },
Condition0%0/2
$self->products->get_all || []
l!l
00
MC/DC0%0/1
$self->products->get_all || []
$self->products->get_all
Truth table0%0/2
A
A= $self->products->get_all
Aresult
11
00
166 ],
167 );
168 }
169  
170 1 1;
171  
« XTaTIK/Model/Blog.pm ↑ Summary XTaTIK/Common.pm »