PageSpeedOnline/Params.pm

filter: Statementstmt 93.8% 46 / 49 Branchbran 73.0% 19 / 26 Conditioncond 77.7% 7 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 85.7% 12 / 14 Podpod 0.0% 0 / 5 totaltotal 79.8% 87 / 109 CC 20 SCAR 18.4
CC
20
Cov
86%
validate
12.3
check_locale
6.0
check_rule
5.2
CRAP 6.3
« PageSpeedOnline.pm ↑ Summary PageSpeedOnline/Advise.pm »
1 package WWW::Google::PageSpeedOnline::Params;
2  
3 4 $WWW::Google::PageSpeedOnline::Params::VERSION = '0.27';
4 4 $WWW::Google::PageSpeedOnline::Params::AUTHORITY = 'cpan:MANWAR';
5  
6 =head1 NAME
7  
8 WWW::Google::PageSpeedOnline::Params - Placeholder for parameters for L<WWW::Google::PageSpeedOnline>.
9  
10 =head1 VERSION
11  
12 Version 0.27
13  
14 =cut
15  
16 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 4 our @EXPORT_OK = qw(validate $FIELDS);
22  
23 4 my $STRATEGIES = { desktop => 1, mobile => 1 };
24  
25 4 my $RULES = {
26 'AVOIDCSSIMPORT' => 1, 'INLINESMALLJAVASCRIPT' => 1, 'SPECIFYCHARSETEARLY' => 1,
27 'SPECIFYACACHEVALIDATOR' => 1, 'SPECIFYIMAGEDIMENSIONS' => 1, 'MAKELANDINGPAGEREDIRECTSCACHEABLE' => 1,
28 'MINIMIZEREQUESTSIZE' => 1, 'PREFERASYNCRESOURCES' => 1, 'MINIFYCSS' => 1,
29 'SERVERESOURCESFROMACONSISTENTURL' => 1, 'MINIFYHTML' => 1, 'OPTIMIZETHEORDEROFSTYLESANDSCRIPTS' => 1,
30 'PUTCSSINTHEDOCUMENTHEAD' => 1, 'MINIMIZEREDIRECTS' => 1, 'INLINESMALLCSS' => 1,
31 'MINIFYJAVASCRIPT' => 1, 'DEFERPARSINGJAVASCRIPT' => 1, 'SPECIFYAVARYACCEPTENCODINGHEADER' => 1,
32 'LEVERAGEBROWSERCACHING' => 1, 'OPTIMIZEIMAGES' => 1, 'SPRITEIMAGES' => 1,
33 'REMOVEQUERYSTRINGSFROMSTATICRESOURCES' => 1, 'SERVESCALEDIMAGES' => 1, 'AVOIDBADREQUESTS' => 1,
34 'USEANAPPLICATIONCACHE' => 1,
35 };
36  
37 4 my $LOCALES = {
38 'ar' => 'Arabic', 'bg' => 'Bulgarian', 'ca' => 'Catalan', 'zh_TW' => 'Traditional Chinese (Taiwan)',
39 'zh_CN' => 'Simplified Chinese', 'fr' => 'Croatian', 'cs' => 'Czech', 'da' => 'Danish',
40 'nl' => 'Dutch', 'en_US' => 'English', 'en_GB' => 'English UK', 'fil' => 'Filipino',
41 'fi' => 'Finnish', 'fr' => 'French', 'de' => 'German', 'el' => 'Greek',
42 'lw' => 'Hebrew', 'hi' => 'Hindi', 'hu' => 'Hungarian', 'id' => 'Indonesian',
43 'it' => 'Italian', 'ja' => 'Japanese', 'ko' => 'Korean', 'lv' => 'Latvian',
44 'lt' => 'Lithuanian', 'no' => 'Norwegian', 'pl' => 'Polish', 'pr_BR' => 'Portuguese (Brazilian)',
45 'pt_PT' => 'Portuguese (Portugal)', 'ro' => 'Romanian', 'ru' => 'Russian', 'sr' => 'Serbian',
46 'sk' => 'Slovakian', 'sl' => 'Slovenian', 'es' => 'Spanish', 'sv' => 'Swedish',
47 'th' => 'Thai', 'tr' => 'Turkish', 'uk' => 'Ukrainian', 'vi' => 'Vietnamese',
48 };
49  
50 sub check_strategy {
51 3 ▶ my ($str) = @_;
Subroutine check_strategy: called CC=2 SCAR=6.9
Pod undocumented
52  
53 die "ERROR: Invalid data type 'strategy' found [$str]"
54 3 ▶ unless exists $STRATEGIES->{lc($str)};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$STRATEGIES{lc $str} 1 2 3
55 }
56  
57 sub check_locale {
58 0 ▶ my ($str) = @_;
Subroutine check_locale: not called CC=2 SCAR=17.9
Pod undocumented
59  
60 die "ERROR: Invalid data type 'locale' found [$str]"
61 0 ▶ unless exists $LOCALES->{$str};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $LOCALES->{$str} 0 0 0
62 }
63  
64 sub check_url {
65 3 ▶ my ($str) = @_;
Subroutine check_url: called CC=3 SCAR=11.1
Pod undocumented
66  
67 3 ▶ die "ERROR: Invalid data type 'url' [$str]" unless (defined $str && $str =~ /^(http(?:s)?\:\/\/[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*\.[a-zA-Z]{2,6}(?:\/?|(?:\/[\w\-]+)*)(?:\/?|\/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$/);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str and $str =~ m[^(http(?:s)?\://[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*\.[a-zA-Z]{2,6}(?:/?|(?:/[\w\-]+)*)(?:/?|/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$] 1 2 3
Condition66%2/3
defined $str and $str =~ m[^(http(?:s)?\://[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*\.[a-zA-Z]{2,6}(?:/?|(?:/[\w\-]+)*)(?:/?|/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$]
!ll&&!rl&&r
012
MC/DC50%1/2
defined $str and $str =~ m[^(http(?:s)?\://[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*\.[a-zA-Z]{2,6}(?:/?|(?:/[\w\-]+)*)(?:/?|/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$]
defined $str $str =~ m[^(http(?:s)?\://[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*\.[a-zA-Z]{2,6}(?:/?|(?:/[\w\-]+)*)(?:/?|/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$]
Truth table66%2/3
A and B
A= defined $strB= $str =~ m[^(http(?:s)?\://[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*\.[a-zA-Z]{2,6}(?:/?|(?:/[\w\-]+)*)(?:/?|/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$]
ABresult
0X0
100
111
68 };
69  
70 sub check_rule {
71 2 ▶ my ($rules) = @_;
Subroutine check_rule: called CC=5 SCAR=16.4
Pod undocumented
72  
73 2 ▶ return unless defined $rules;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rules 0 2 2
74 2 ▶ die "ERROR: 'Rules' should be passed in as arrayref" unless (ref($rules) eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $rules eq "ARRAY" 1 1 2
75  
76 1 foreach my $rule (@$rules) {
77 1 ▶ die "ERROR: Invalid 'rule' found [$rule]" unless (exists $RULES->{uc($rule)});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$RULES{uc $rule} 1 0 1
78 }
79 }
80  
81 our $FIELDS = {
82 3 ▶ 'strategy' => { check => sub { check_strategy(@_) }, type => 's' },
Subroutine __ANON__: called CC=1 SCAR=0.0
83 0 ▶ 'locale' => { check => sub { check_locale(@_) }, type => 's' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
84 3 ▶ 'url' => { check => sub { check_url(@_) }, type => 's' },
Subroutine __ANON__: called CC=1 SCAR=0.0
85 2 ▶ 'rule' => { check => sub { check_rule(@_) }, type => 's' },
Subroutine __ANON__: called CC=1 SCAR=0.0
86 };
87  
88 sub validate {
89 7 ▶ my ($fields, $params) = @_;
Subroutine validate: called CC=12 SCAR=25.1
Pod undocumented
90  
91 7 ▶ die "ERROR: Missing params list." unless (defined $params);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params 0 7 7
92  
93 7 ▶ die "ERROR: Parameters have to be hash ref" unless (ref($params) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $params eq "HASH" 1 6 7
94  
95 6 foreach my $key (keys %{$params}) {
96 die "ERROR: Received invalid param: $key"
97 14 ▶ unless (exists $FIELDS->{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $WWW::Google::PageSpeedOnline::Params::FIELDS->{$key} 1 13 14
98 }
99  
100 5 foreach my $key (keys %{$fields}) {
101 die "ERROR: Received invalid param: $key"
102 13 ▶ unless (exists $FIELDS->{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $WWW::Google::PageSpeedOnline::Params::FIELDS->{$key} 0 13 13
103  
104 die "ERROR: Missing mandatory param: $key"
105 13 ▶ if ($fields->{$key} && !exists $params->{$key});
Branch: 1 branch
BranchTrueFalseTotal
if $fields->{$key} and not exists $params->{$key} 1 12 13
Condition100%3/3
$fields->{$key} and not exists $params->{$key}
!ll&&!rl&&r
931
MC/DC100%2/2
$fields->{$key} and not exists $params->{$key}
$fields->{$key} not exists $params->{$key}
Truth table100%3/3
A and not(B)
A= $fields->{$key}B= not exists $params->{$key}
ABresult
0X0
100
111
106  
107 die "ERROR: Received undefined mandatory param: $key"
108 12 ▶ if ($fields->{$key} && !defined $params->{$key});
Branch: 1 branch
BranchTrueFalseTotal
if $fields->{$key} and not defined $params->{$key} 0 12 12
Condition66%2/3
$fields->{$key} and not defined $params->{$key}
!ll&&!rl&&r
930
MC/DC0%0/2
$fields->{$key} and not defined $params->{$key}
$fields->{$key} not defined $params->{$key}
Truth table66%2/3
A and not(B)
A= $fields->{$key}B= not defined $params->{$key}
ABresult
0X0
100
111
109  
110 $FIELDS->{$key}->{check}->($params->{$key})
111 12 ▶ if defined $params->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{$key} 8 4 12
112 }
113 }
114  
115 =head1 AUTHOR
116  
117 Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
118  
119 =head1 REPOSITORY
120  
121 L<https://github.com/manwar/WWW-Google-PageSpeedOnline>
122  
123 =head1 BUGS
124  
125 Please report any bugs or feature requests to C<bug-www-google-pagespeedonline at
126 rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Google-PageSpeedOnline>.
127 I will be notified, and then you'll automatically be notified of progress on your
128 bug as I make changes.
129  
130 =head1 SUPPORT
131  
132 You can find documentation for this module with the perldoc command.
133  
134 perldoc WWW::Google::PageSpeedOnline::Params
135  
136 You can also look for information at:
137  
138 =over 4
139  
140 =item * RT: CPAN's request tracker (report bugs here)
141  
142 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Google-PageSpeedOnline>
143  
144 =item * AnnoCPAN: Annotated CPAN documentation
145  
146 L<http://annocpan.org/dist/WWW-Google-PageSpeedOnline>
147  
148 =item * CPAN Ratings
149  
150 L<http://cpanratings.perl.org/d/WWW-Google-PageSpeedOnline>
151  
152 =item * Search CPAN
153  
154 L<http://search.cpan.org/dist/WWW-Google-PageSpeedOnline/>
155  
156 =back
157  
158 =head1 LICENSE AND COPYRIGHT
159  
160 Copyright (C) 2011 - 2015 Mohammad S Anwar.
161  
162 This program is free software; you can redistribute it and/or modify it under
163 the terms of the the Artistic License (2.0). You may obtain a copy of the full
164 license at:
165  
166 L<http://www.perlfoundation.org/artistic_license_2_0>
167  
168 Any use, modification, and distribution of the Standard or Modified Versions is
169 governed by this Artistic License.By using, modifying or distributing the Package,
170 you accept this license. Do not use, modify, or distribute the Package, if you do
171 not accept this license.
172  
173 If your Modified Version has been derived from a Modified Version made by someone
174 other than you,you are nevertheless required to ensure that your Modified Version
175 complies with the requirements of this license.
176  
177 This license does not grant you the right to use any trademark, service mark,
178 tradename, or logo of the Copyright Holder.
179  
180 This license includes the non-exclusive, worldwide, free-of-charge patent license
181 to make, have made, use, offer to sell, sell, import and otherwise transfer the
182 Package with respect to any patent claims licensable by the Copyright Holder that
183 are necessarily infringed by the Package. If you institute patent litigation
184 (including a cross-claim or counterclaim) against any party alleging that the
185 Package constitutes direct or contributory patent infringement,then this Artistic
186 License to you shall terminate on the date that such litigation is filed.
187  
188 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
189 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
190 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
191 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
192 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
193 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
194 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
195  
196 =cut
197  
198 4 1; # End of WWW::Google::PageSpeedOnline::Params
« PageSpeedOnline.pm ↑ Summary PageSpeedOnline/Advise.pm »