XTaTIK/Controller/Root.pm

filter: Statementstmt 25.0% 11 / 44 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 33.3% 3 / 9 Podpod 0.0% 0 / 6 totaltotal 19.1% 14 / 73 CC 11 SCAR 23.1
CC
11
Cov
19%
products_category
20.0
contact_post
12.0
sitemap
12.0
CRAP 10.1
« XTaTIK/Utilities/Misc.pm ↑ Summary XTaTIK/Utilities/ToadFarmer.pm »
1 package XTaTIK::Controller::Root;
2  
3 1 our $VERSION = '0.004001'; # 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 sub index {
10 0 ▶ my $self = shift;
Subroutine index: not called CC=2 SCAR=17.9
Pod undocumented
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 sub products_category {
21 0 ▶ my $self = shift;
Subroutine products_category: not called CC=4 SCAR=30.0
Pod undocumented
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 $_->{contents}->@*;
30 }
31  
32 $self->stash(
33 0 products => $products,
34 return_path => $return_path,
35 return_name => $return_name,
36 );
37 }
38  
39 sub product {
40 0 ▶ my $self = shift;
Subroutine product: not called CC=2 SCAR=17.9
Pod undocumented
41 0 my ( $product ) = $self->products->get_by_url( $self->stash('url') );
42 0 ▶ $product or $self->reply->not_found;
Branch: 1 branch
BranchTrueFalseTotal
$product or $self->reply->not_found 0 0 0
43  
44 0 set_product_pic( $self, @$product{qw/image number/} );
45  
46 0 $self->stash( product => $product );
47 };
48  
49 sub contact_post {
50 0 ▶ my $self = shift;
Subroutine contact_post: not called CC=3 SCAR=24.8
Pod undocumented
51  
52 0 $self->form_checker(
53 rules => {
54 name => { max => 200, },
55 email => { max => 200, },
56 province => {
57 valid_values => [
58 qw/AB BC MB NB NF NT NS NU ON PE QC SK YT/
59 ],
60 valid_values_error => 'Please choose your province',
61 },
62 message => { max => 100_000 },
63 },
64 );
65  
66 0 ▶ return $self->render( template => 'root/contact' )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->form_checker_ok 0 0 0
67 unless $self->form_checker_ok;
68  
69 # Check CSRF token
70 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
71 if $self->validation->csrf_protect->has_error('csrf_token');
72  
73 0 $self->stash( visitor_ip => $self->tx->remote_address );
74 0 $self->stash( message => n_to_br( $self->param('message')) );
75  
76 $self->mail(
77 test => $self->config('mail')->{test},
78 to => $self->config('mail')->{to}{quicknote},
79 from => $self->config('mail')->{from}{quicknote},
80 subject => 'Quicknote from '
81 . $self->config('text')->{website_domain},
82  
83 0 type => 'text/html',
84 data => $self->render_to_string('email-templates/quicknote'),
85 );
86  
87 0 return $self->render( template => 'root/contact' );
88 }
89  
90 sub feedback_post {
91 0 ▶ my $self = shift;
Subroutine feedback_post: not called CC=2 SCAR=17.9
Pod undocumented
92  
93 0 $self->form_checker(
94 rules => {
95 email => { max => 200, optional => 1, },
96 feedback => { max => 100_000, },
97 },
98 );
99  
100 0 ▶ return $self->render( template => 'root/feedback' )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->form_checker_ok 0 0 0
101 unless $self->form_checker_ok;
102  
103 0 $self->stash(
104 visitor_ip => $self->tx->remote_address,
105 feedback => n_to_br( $self->param('feedback') ),
106 );
107  
108 $self->mail(
109 test => $self->config('mail')->{test},
110 to => $self->config('mail')->{to}{feedback},
111 from => $self->config('mail')->{from}{feedback},
112 subject => 'Site Feedback from '
113 . $self->config('text')->{website_domain},
114  
115 0 type => 'text/html',
116 data => $self->render_to_string('email-templates/feedback'),
117 );
118  
119 0 return $self->render( template => 'root/feedback' );
120 }
121  
122 sub sitemap {
123 0 ▶ my $self = shift;
Subroutine sitemap: not called CC=3 SCAR=24.8
Pod undocumented
124  
125 $self->stash(
126 urls => [
127 map +{
128 freq => 'weekly',
129 priority => '0.9',
130 url => $self->xtext('website_proto')
131 . '://'
132 . $self->xtext('website_domain')
133 . $_,
134 }, qw{
135 /
136 /blog
137 /history
138 /about
139 /contact
140 },
141 0 ▶ ( map '/blog/' . $_->{url}, @{$self->blog->brief_list ||[]}),
Branch: 1 branch
BranchTrueFalseTotal
$self->blog->brief_list or [] 0 0 0
142 0 ▶ map '/product/' . $_->{url}, @{ $self->products->get_all||[] },
Branch: 1 branch
BranchTrueFalseTotal
$self->products->get_all or [] 0 0 0
143 ],
144 );
145 }
146  
147 1 1;
148  
« XTaTIK/Utilities/Misc.pm ↑ Summary XTaTIK/Utilities/ToadFarmer.pm »