blib/lib/WWW/Shopify/Field.pm

filter: Statementstmt 52.8% 111 / 210 Branchbran 12.0% 6 / 50 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 37.2% 38 / 102 Podpod 0.0% 0 / 20 totaltotal 38.6% 155 / 401 CC 30 SCAR 15.9
CC
30
Cov
43%
validate
20.0
to_shopify
20.0
from_shopify
20.0
CRAP 4.9
« blib/lib/WWW/Shopify/Model/Shop.pm ↑ Summary blib/lib/WWW/Shopify/Exception.pm »
1 #!/usr/bin/perl
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use WWW::Shopify::Field::Text;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use WWW::Shopify::Field::Relation;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use WWW::Shopify::Field::String;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use WWW::Shopify::Field::Identifier;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 package main;
12 1 ▶use String::Random qw(random_regex random_string);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Data::Random qw(rand_datetime rand_words);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head2 WWW::Shopify::Model::Field
16  
17 The main object representing a field on a Shopify object. Contains mainly a name, and a type. Can also contain more data when the need arises to represent something more specifically.
18  
19 There are a lot of these, so I'm not going to list them; most of the distinctions are made so that databases with reasonable data can be generated.
20  
21 =cut
22  
23  
24 package WWW::Shopify::Field;
25 sub new($) {
26 562 ▶ my $package = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
27 562 my $calling_package = caller(0);
28 562 return bless {
29 arguments => [@_],
30 name => undef,
31 owner => $calling_package
32 }, $package;
33 }
34 675 ▶sub name { $_[0]->{name} = $_[1] if defined $_[1]; return $_[0]->{name}; }
Subroutine name: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[1] 644 31 675
35 0 ▶sub sql_type($) { die ref($_[0]); }
Subroutine sql_type: not called CC=1 SCAR=6.9
Pod undocumented
36 1161 ▶sub is_relation { return undef; }
Subroutine is_relation: called CC=1 SCAR=0.0
Pod undocumented
37 0 ▶sub is_qualifier { return undef; }
Subroutine is_qualifier: not called CC=1 SCAR=6.9
Pod undocumented
38 0 ▶sub qualifier { return undef; }
Subroutine qualifier: not called CC=1 SCAR=6.9
Pod undocumented
39 0 ▶sub to_shopify($$) { return $_[1]; }
Subroutine to_shopify: not called CC=1 SCAR=6.9
Pod undocumented
40 0 ▶sub from_shopify($$) { return $_[1]; }
Subroutine from_shopify: not called CC=1 SCAR=6.9
Pod undocumented
41 0 ▶sub generate($) { die "Can't generate $_[0]"; }
Subroutine generate: not called CC=1 SCAR=6.9
Pod undocumented
42 0 ▶sub validate($) { die "Can't validate $_[0]"; }
Subroutine validate: not called CC=1 SCAR=6.9
Pod undocumented
43 0 ▶sub owner { $_[0]->{owner} = $_[1] if defined $_[1]; return $_[0]->{owner}; }
Subroutine owner: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[1] 0 0 0
44  
45 0 ▶sub is_db_belongs_to { return undef; }
Subroutine is_db_belongs_to: not called CC=1 SCAR=6.9
Pod undocumented
46 0 ▶sub is_db_has_many { return undef; }
Subroutine is_db_has_many: not called CC=1 SCAR=6.9
Pod undocumented
47 0 ▶sub is_db_many_many { return undef; }
Subroutine is_db_many_many: not called CC=1 SCAR=6.9
Pod undocumented
48 0 ▶sub is_db_has_one { return undef; }
Subroutine is_db_has_one: not called CC=1 SCAR=6.9
Pod undocumented
49  
50 use constant {
51 1 TYPE_QUANTITATIVE => 0,
52 TYPE_QUALITATIVE => 1,
53 TYPE_BOOLEAN => 2
54 1 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 use constant {
57 # No order, no set distance (E.G. Telephone Numbers)
58 1 SET_NOMINAL => 0,
59 # No set distance between values.
60 SET_ORDINAL => 1,
61 # Distinguishable distance between values. (E.G. Real Numbers)
62 SET_CARDINAL => 2
63 1 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 1 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
66 1 our @EXPORT_OK = qw(TYPE_QUANTITATIVE TYPE_QUALITATIVE TYPE_BOOLEAN SET_NOMINAL SET_ORDINAL SET_CARDINAL);
67  
68 0 ▶sub data_type { return TYPE_QUALITATIVE; }
Subroutine data_type: not called CC=1 SCAR=6.9
Pod undocumented
69 0 ▶sub is_qualitative { return $_[0]->data_type == TYPE_QUANTITATIVE; }
Subroutine is_qualitative: not called CC=1 SCAR=6.9
Pod undocumented
70 0 ▶sub is_quantitative { return $_[0]->data_type == TYPE_QUALITATIVE; }
Subroutine is_quantitative: not called CC=1 SCAR=6.9
Pod undocumented
71 0 ▶sub is_boolean { return $_[0]->data_type == TYPE_BOOLEAN; }
Subroutine is_boolean: not called CC=1 SCAR=6.9
Pod undocumented
72 0 ▶sub number_type { return $_[0]->is_quantitative ? SET_CARDINAL : SET_NOMINAL }
Subroutine number_type: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->is_quantitative ? : 0 0 0
73  
74 package WWW::Shopify::Field::Hook;
75 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
76 0 ▶sub new($) { return bless { internal => $_[1], qualifier => $_[2] }, $_[0]; }
Subroutine new: not called CC=1 SCAR=6.9
77 0 ▶sub sql_type($) { return shift->{internal}->sql_type(@_); }
Subroutine sql_type: not called CC=1 SCAR=6.9
78 0 ▶sub is_relation { return shift->{internal}->is_relation(@_); }
Subroutine is_relation: not called CC=1 SCAR=6.9
79 0 ▶sub to_shopify($$) { return shift->{internal}->to_shopify(@_); }
Subroutine to_shopify: not called CC=1 SCAR=6.9
80 0 ▶sub from_shopify($$) { return shift->{internal}->from_shopify(@_); }
Subroutine from_shopify: not called CC=1 SCAR=6.9
81 0 ▶sub generate($) { return shift->{internal}->generate(@_); }
Subroutine generate: not called CC=1 SCAR=6.9
82 0 ▶sub relation($) { return shift->{internal}->relation(@_); }
Subroutine relation: not called CC=1 SCAR=6.9
83 0 ▶sub is_many { return shift->{internal}->is_many(@_); }
Subroutine is_many: not called CC=1 SCAR=6.9
84 0 ▶sub is_one { return shift->{internal}->is_one(@_); }
Subroutine is_one: not called CC=1 SCAR=6.9
85 0 ▶sub is_own { return shift->{internal}->is_own(@_); }
Subroutine is_own: not called CC=1 SCAR=6.9
86 0 ▶sub is_reference { return shift->{internal}->is_reference(@_); }
Subroutine is_reference: not called CC=1 SCAR=6.9
87  
88 package WWW::Shopify::Field::Int;
89 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
90 1 ▶use String::Numeric qw(is_int);
Subroutine BEGIN: called CC=1 SCAR=0.0
91 0 ▶sub sql_type { return "int"; }
Subroutine sql_type: not called CC=1 SCAR=6.9
92 sub generate($) {
93 0 ▶ return int(rand(10000)) if (int(@{$_[0]->{arguments}}) == 0);
Subroutine generate: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
if int @{$_[0]{"arguments"};} == 0 0 0 0
94 0 ▶ return $_[0]->{arguments}->[0] if (int(@{$_[0]->{arguments}}) == 1);
Branch: 1 branch
BranchTrueFalseTotal
if int @{$_[0]{"arguments"};} == 1 0 0 0
95 0 return int(rand($_[0]->{arguments}->[1] - $_[0]->{arguments}->[0] + 1) + $_[0]->{arguments}->[0]);
96 }
97 0 ▶sub data_type { return WWW::Shopify::Field::TYPE_QUANTITATIVE; }
Subroutine data_type: not called CC=1 SCAR=6.9
98 0 ▶sub validate($$) { return is_int($_[1]); }
Subroutine validate: not called CC=1 SCAR=6.9
99  
100 package WWW::Shopify::Field::BigInt;
101 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
102 1 ▶use String::Numeric qw(is_int);
Subroutine BEGIN: called CC=1 SCAR=0.0
103 0 ▶sub sql_type { return "bigint"; }
Subroutine sql_type: not called CC=1 SCAR=6.9
104 sub generate($) {
105 0 ▶ return int(rand(10000000)) if (int(@{$_[0]->{arguments}}) == 0);
Subroutine generate: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
if int @{$_[0]{"arguments"};} == 0 0 0 0
106 0 ▶ return $_[0]->{arguments}->[0] if (int(@{$_[0]->{arguments}}) == 1);
Branch: 1 branch
BranchTrueFalseTotal
if int @{$_[0]{"arguments"};} == 1 0 0 0
107 0 return int(rand($_[0]->{arguments}->[1] - $_[0]->{arguments}->[0] + 1) + $_[0]->{arguments}->[0]);
108 }
109 0 ▶sub data_type { return WWW::Shopify::Field::TYPE_QUANTITATIVE; }
Subroutine data_type: not called CC=1 SCAR=6.9
110 0 ▶sub validate { return is_int($_[1]); }
Subroutine validate: not called CC=1 SCAR=6.9
111  
112 package WWW::Shopify::Field::Boolean;
113 1 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
114 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
115 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
116 0 ▶sub sql_type { return "bool"; }
Subroutine sql_type: not called CC=1 SCAR=6.9
117 1 ▶sub generate { return (rand() < 0.5); }
Subroutine generate: called CC=1 SCAR=0.0
118 0 ▶sub validate { return looks_like_number($_[1]) ? ($_[1] == 0 || $_[1] == 1) : (lc($_[1]) == 'true' || lc($_[1]) == 'false'); }
Subroutine validate: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
&looks_like_number($_[1]) ? : 0 0 0
Condition0%0/6
$_[1] == 0 or $_[1] == 1
l!l&&r!l&&!r
000
lc $_[1] == "true" or lc $_[1] == "false"
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[1] == 0 or $_[1] == 1
$_[1] == 0 $_[1] == 1
MC/DC0%0/2
lc $_[1] == "true" or lc $_[1] == "false"
lc $_[1] == "true" lc $_[1] == "false"
Truth table0%0/3
A or B
A= $_[1] == 0B= $_[1] == 1
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= lc $_[1] == "true"B= lc $_[1] == "false"
ABresult
1X1
011
000
119 0 ▶sub data_type { return WWW::Shopify::Field::TYPE_BOOLEAN; }
Subroutine data_type: not called CC=1 SCAR=6.9
120 0 ▶sub to_shopify { return $_[1] ? JSON::true : JSON::false; }
Subroutine to_shopify: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 0 0 0
121  
122 package WWW::Shopify::Field::Float;
123 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
124 1 ▶use String::Numeric qw(is_float);
Subroutine BEGIN: called CC=1 SCAR=0.0
125 0 ▶sub sql_type { return "float"; }
Subroutine sql_type: not called CC=1 SCAR=6.9
126 sub generate($) {
127 2 ▶ return rand() * 10000.0 if (int(@{$_[0]->{arguments}}) == 0);
Subroutine generate: called CC=3 SCAR=17.3
Branch: 1 branch
BranchTrueFalseTotal
if int @{$_[0]{"arguments"};} == 0 2 0 2
128 0 ▶ return $_[0]->{arguments}->[0] if (int(@{$_[0]->{arguments}}) == 1);
Branch: 1 branch
BranchTrueFalseTotal
if int @{$_[0]{"arguments"};} == 1 0 0 0
129 0 return rand($_[0]->{arguments}->[1] - $_[0]->{arguments}->[0] + 1) + $_[0]->{arguments}->[0];
130 }
131 0 ▶sub data_type { return WWW::Shopify::Field::TYPE_QUANTITATIVE; }
Subroutine data_type: not called CC=1 SCAR=6.9
132 0 ▶sub validate($$) { return is_float($_[1]); }
Subroutine validate: not called CC=1 SCAR=6.9
133  
134 package WWW::Shopify::Field::Timezone;
135 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
136 0 ▶sub sql_type { return "varchar(255)"; }
Subroutine sql_type: not called CC=1 SCAR=6.9
137  
138 1 my %from_shopify_timezones = (
139 "(GMT-05:00) Eastern Time (US & Canada)" => "America/New_York" ,
140 "(GMT-11:00) International Date Line West" => "-1100",
141 "(GMT-11:00) Midway Island" => "Pacific/Midway",
142 "(GMT-11:00) American Samoa" => "Pacific/Pago_Pago",
143 "(GMT-10:00) Hawaii" => "Pacific/Honolulu",
144 "(GMT-09:00) Alaska" => "America/Anchorage",
145 "(GMT-08:00) Pacific Time (US & Canada)" => "PST8PDT",
146 "(GMT-08:00) Tijuana" => "America/Tijuana",
147 "(GMT-07:00) Mountain Time (US & Canada)" => "MST7MDT",
148 "(GMT-07:00) Arizona" => "MST",
149 "(GMT-07:00) Chihuahua" => "America/Chihuahua",
150 "(GMT-07:00) Mazatlan" => "MST",
151 "(GMT-06:00) Central Time (US & Canada)" => "CST6CDT",
152 "(GMT-06:00) Saskatchewan" => "-0600",
153 "(GMT-06:00) Guadalajara" => "CST6CDT",
154 "(GMT-06:00) Mexico City" => "CST6CDT",
155 "(GMT-06:00) Monterrey" => "America/Monterrey",
156 "(GMT-06:00) Central America" => "CST6CDT",
157 "(GMT-05:00) Indiana (East)" => "EST5EDT",
158 "(GMT-05:00) Bogota" => "America/Bogota",
159 "(GMT-05:00) Lima" => "America/Lima",
160 "(GMT-05:00) Quito" => "-0500",
161 "(GMT-04:00) Atlantic Time (Canada)" => "America/Halifax",
162 "(GMT-04:30) Caracas" => "America/Caracas",
163 "(GMT-04:00) La Paz" => "-04:00",
164 "(GMT-04:00) Santiago" => "America/Santiago",
165 "(GMT-03:30) Newfoundland" => "America/La_Paz",
166 "(GMT-03:00) Brasilia" => "America/Sao_Paulo",
167 "(GMT-03:00) Buenos Aires" => "America/Argentina/Buenos_Aires",
168 "(GMT-04:00) Georgetown" => "America/Guyana",
169 "(GMT-03:00) Greenland" => "-0300",
170 "(GMT-02:00) Mid-Atlantic" => "-0200",
171 "(GMT-01:00) Azores" => "Atlantic/Azores",
172 "(GMT-01:00) Cape Verde Is." => "Atlantic/Cape_Verde",
173 "(GMT+00:00) Dublin" => "Europe/Dublin",
174 "(GMT+00:00) Edinburgh" => "Europe/London",
175 "(GMT+00:00) Lisbon" => "Europe/Lisbon",
176 "(GMT+00:00) London" => "Europe/London",
177 "(GMT+00:00) Casablanca" => "Africa/Casablanca",
178 "(GMT+00:00) Monrovia" => "Africa/Monrovia",
179 "(GMT+00:00) UTC" => "UTC",
180 "(GMT+01:00) Belgrade" => "Europe/Belgrade",
181 "(GMT+01:00) Bratislava" => "Europe/Bratislava",
182 "(GMT+01:00) Budapest" => "Europe/Budapest",
183 "(GMT+01:00) Ljubljana" => "Europe/Ljubljana",
184 "(GMT+01:00) Prague" => "Europe/Prague",
185 "(GMT+01:00) Sarajevo" => "Europe/Sarajevo",
186 "(GMT+01:00) Skopje" => "Europe/Skopje",
187 "(GMT+01:00) Warsaw" => "Europe/Warsaw",
188 "(GMT+01:00) Zagreb" => "Europe/Zagreb",
189 "(GMT+01:00) Brussels" => "Europe/Brussels",
190 "(GMT+01:00) Copenhagen" => "Europe/Copenhagen",
191 "(GMT+01:00) Madrid" => "Europe/Madrid",
192 "(GMT+01:00) Paris" => "Europe/Paris",
193 "(GMT+01:00) Amsterdam" => "Europe/Amsterdam",
194 "(GMT+01:00) Berlin" => "Europe/Berlin",
195 "(GMT+01:00) Bern" => "Europe/Zurich",
196 "(GMT+01:00) Rome" => "Europe/Rome",
197 "(GMT+01:00) Stockholm" => "Europe/Stockholm",
198 "(GMT+01:00) Vienna" => "Europe/Vienna",
199 "(GMT+01:00) West Central Africa" => "+0100",
200 "(GMT+02:00) Bucharest" => "Europe/Bucharest",
201 "(GMT+02:00) Cairo" => "Africa/Cairo",
202 "(GMT+02:00) Helsinki" => "Europe/Helsinki",
203 "(GMT+02:00) Kyiv" => "Europe/Kiev",
204 "(GMT+02:00) Riga" => "Europe/Riga",
205 "(GMT+02:00) Sofia" => "Europe/Sofia",
206 "(GMT+02:00) Tallinn" => "Europe/Tallinn",
207 "(GMT+02:00) Vilnius" => "Europe/Vilnius",
208 "(GMT+02:00) Athens" => "Europe/Athens",
209 "(GMT+02:00) Istanbul" => "Europe/Istanbul",
210 "(GMT+03:00) Minsk" => "Europe/Minsk",
211 "(GMT+02:00) Jerusalem" => "Asia/Jerusalem",
212 "(GMT+02:00) Harare" => "Africa/Harare",
213 "(GMT+02:00) Pretoria" => "Africa/Maseru",
214 "(GMT+04:00) Moscow" => "Europe/Moscow",
215 "(GMT+04:00) St. Petersburg" => "Europe/Moscow",
216 "(GMT+04:00) Volgograd" => "Europe/Volgograd",
217 "(GMT+03:00) Kuwait" => "Asia/Kuwait",
218 "(GMT+03:00) Riyadh" => "Asia/Riyadh",
219 "(GMT+03:00) Nairobi" => "Africa/Nairobi",
220 "(GMT+03:00) Baghdad" => "Asia/Baghdad",
221 "(GMT+03:30) Tehran" => "Asia/Tehran",
222 "(GMT+04:00) Abu Dhabi" => "+0400",
223 "(GMT+04:00) Muscat" => "Asia/Muscat",
224 "(GMT+04:00) Baku" => "Asia/Baku",
225 "(GMT+04:00) Tbilisi" => "Asia/Tbilisi",
226 "(GMT+04:00) Yerevan" => "Asia/Yerevan",
227 "(GMT+04:30) Kabul" => "Asia/Kabul",
228 "(GMT+06:00) Ekaterinburg" => "Asia/Yekaterinburg",
229 "(GMT+05:00) Islamabad" => "+05:00",
230 "(GMT+05:00) Karachi" => "Asia/Karachi",
231 "(GMT+05:00) Tashkent" => "Asia/Tashkent",
232 "(GMT+05:30) Chennai" => "+05:30",
233 "(GMT+05:30) Kolkata" => "Asia/Kolkata",
234 "(GMT+05:30) Mumbai" => "+05:30",
235 "(GMT+05:30) New Delhi" => "+05:30",
236 "(GMT+05:45) Kathmandu" => "Asia/Kathmandu",
237 "(GMT+06:00) Astana" => "Asia/Thimphu",
238 "(GMT+06:00) Dhaka" => "Asia/Dhaka",
239 "(GMT+05:30) Sri Jayawardenepura" => "+0530",
240 "(GMT+06:00) Almaty" => "Asia/Almaty",
241 "(GMT+07:00) Novosibirsk" => "Asia/Novosibirsk",
242 "(GMT+06:30) Rangoon" => "Asia/Rangoon",
243 "(GMT+07:00) Bangkok" => "Asia/Bangkok",
244 "(GMT+07:00) Hanoi" => "+0700",
245 "(GMT+07:00) Jakarta" => "Asia/Jakarta",
246 "(GMT+08:00) Krasnoyarsk" => "Asia/Krasnoyarsk",
247 "(GMT+08:00) Beijing" => "Asia/Shanghai",
248 "(GMT+08:00) Chongqing" => "Asia/Chongqing",
249 "(GMT+08:00) Hong Kong" => "Asia/Hong_Kong",
250 "(GMT+08:00) Urumqi" => "Asia/Urumqi",
251 "(GMT+08:00) Kuala Lumpur" => "Asia/Kuala_Lumpur",
252 "(GMT+08:00) Singapore" => "Asia/Singapore",
253 "(GMT+08:00) Taipei" => "Asia/Taipei",
254 "(GMT+08:00) Perth" => "Australia/Perth",
255 "(GMT+09:00) Irkutsk" => "Asia/Irkutsk",
256 "(GMT+08:00) Ulaan Bataar" => "Asia/Ulaanbaatar",
257 "(GMT+09:00) Seoul" => "Asia/Seoul",
258 "(GMT+09:00) Osaka" => "Asia/Tokyo",
259 "(GMT+09:00) Sapporo" => "Asia/Tokyo",
260 "(GMT+09:00) Tokyo" => "Asia/Tokyo",
261 "(GMT+10:00) Yakutsk" => "Asia/Yakutsk",
262 "(GMT+09:30) Darwin" => "Australia/Darwin",
263 "(GMT+09:30) Adelaide" => "Australia/Adelaide",
264 "(GMT+10:00) Canberra" => "Australia/Canberra",
265 "(GMT+10:00) Melbourne" => "Australia/Melbourne",
266 "(GMT+10:00) Sydney" => "Australia/Sydney",
267 "(GMT+10:00) Brisbane" => "Australia/Brisbane",
268 "(GMT+10:00) Hobart" => "Australia/Hobart",
269 "(GMT+11:00) Vladivostok" => "Asia/Vladivostok",
270 "(GMT+10:00) Guam" => "Pacific/Guam",
271 "(GMT+10:00) Port Moresby" => "Pacific/Port_Moresby",
272 "(GMT+12:00) Magadan" => "Asia/Magadan",
273 "(GMT+12:00) Solomon Is." => "+1100",
274 "(GMT+11:00) New Caledonia" => "+1100",
275 "(GMT+12:00) Fiji" => "Pacific/Fiji",
276 "(GMT+12:00) Kamchatka" => "Asia/Kamchatka",
277 "(GMT+12:00) Marshall Is." => "Pacific/Majuro",
278 "(GMT+12:00) Auckland" => "Pacific/Auckland",
279 "(GMT+12:00) Wellington" => "Pacific/Auckland",
280 "(GMT+13:00) Nuku'alofa" => "Pacific/Tongatapu",
281 "(GMT+13:00) Tokelau Is." => "Pacific/Fakaofo",
282 "(GMT+13:00) Samoa" => "Pacific/Apia"
283 );
284 1 my %to_shopify_timezones = reverse(%from_shopify_timezones);
285  
286 0 ▶sub timezone_mapping { return \%to_shopify_timezones; }
Subroutine timezone_mapping: not called CC=1 SCAR=6.9
287 0 ▶sub shopify_timezones { return keys(%from_shopify_timezones); }
Subroutine shopify_timezones: not called CC=1 SCAR=6.9
288  
289 sub to_shopify {
290 0 ▶ my $dttz = $_[1];
Subroutine to_shopify: not called CC=3 SCAR=24.8
291 0 ▶ return undef unless $dttz;
Branch: 1 branch
BranchTrueFalseTotal
unless $dttz 0 0 0
292 0 my $mapping = $to_shopify_timezones{$dttz->name};
293 0 ▶ $mapping = "(GMT+00:00) UTC" unless $mapping;
Branch: 1 branch
BranchTrueFalseTotal
unless $mapping 0 0 0
294 0 return $mapping;
295 }
296  
297 sub from_shopify {
298 0 ▶ my $dttz = $_[1];
Subroutine from_shopify: not called CC=3 SCAR=24.8
299 0 ▶ return undef unless $dttz;
Branch: 1 branch
BranchTrueFalseTotal
unless $dttz 0 0 0
300 0 my $mapping = $from_shopify_timezones{$dttz};
301 0 ▶ $mapping = "UTC" unless $mapping;
Branch: 1 branch
BranchTrueFalseTotal
unless $mapping 0 0 0
302 0 return DateTime::TimeZone->new(name => $mapping);
303 }
304  
305 sub generate {
306 1 ▶ my @timezones = keys(%from_shopify_timezones);
Subroutine generate: called CC=1 SCAR=0.0
307 1 return $timezones[int(rand(@timezones))];
308 }
309  
310  
311 package WWW::Shopify::Field::Currency;
312 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
313 0 ▶sub sql_type { return "varchar(255)"; }
Subroutine sql_type: not called CC=1 SCAR=6.9
314 1 ▶sub generate($) { return rand() < 0.5 ? "USD" : "CAD"; }
Subroutine generate: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
rand() < 0.5 ? : 0 1 1
315  
316 package WWW::Shopify::Field::Money;
317 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
318 1 ▶use String::Numeric qw(is_float);
Subroutine BEGIN: called CC=1 SCAR=0.0
319 0 ▶sub sql_type { return "decimal(10,2)"; }
Subroutine sql_type: not called CC=1 SCAR=6.9
320 0 ▶sub generate($) { return sprintf("%.2f", rand(500)); }
Subroutine generate: not called CC=1 SCAR=6.9
321 0 ▶sub validate($) { return undef unless $_[1] =~ m/\s*\$?\s*$/; return is_float($`); }
Subroutine validate: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1] =~ /\s*\$?\s*$/ 0 0 0
322 0 ▶sub data_type { return WWW::Shopify::Field::TYPE_QUANTITATIVE; }
Subroutine data_type: not called CC=1 SCAR=6.9
323  
324 package WWW::Shopify::Field::Money::USD;
325 1 ▶use parent -norequire, 'WWW::Shopify::Field::Money';
Subroutine BEGIN: called CC=1 SCAR=0.0
326  
327 package WWW::Shopify::Field::Date;
328 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
329 1 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
330 0 ▶sub sql_type { return 'datetime'; }
Subroutine sql_type: not called CC=1 SCAR=6.9
331 sub to_shopify {
332 0 ▶ my $dt = $_[1];
Subroutine to_shopify: not called CC=4 SCAR=30.0
333 0 ▶ return undef unless $dt;
Branch: 1 branch
BranchTrueFalseTotal
unless $dt 0 0 0
334 0 ▶ if (ref($dt) eq "DateTime") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dt eq "DateTime") 0 0 0
335 0 my $t = $dt->strftime('%Y-%m-%dT%H:%M:%S%z');
336 0 $t =~ s/(\d\d)$/:$1/;
337 0 return $t;
338 }
339 0 ▶ die new WWW::Shopify::Exception($dt) unless $dt =~ m/([\d-]+)\s*T?\s*([\d:]+)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $dt =~ /([\d-]+)\s*T?\s*([\d:]+)/ 0 0 0
340 0 return "$1T$2";
341 }
342 sub from_shopify {
343 0 ▶ my $dt;
Subroutine from_shopify: not called CC=4 SCAR=30.0
344 0 ▶ return undef unless $_[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1] 0 0 0
345 0 ▶ if ($_[1] =~ m/(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)([+-]\d+):(\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] =~ /(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)([+-]\d+):(\d+)/) { } 0 0 0
346 0 $dt = DateTime->new(
347 year => $1,
348 month => $2,
349 day => $3,
350 hour => $4,
351 minute => $5,
352 second => $6,
353 time_zone => $7 . $8,
354 );
355 }
356 else {
357 0 ▶ die new WWW::Shopify::Exception("Unable to parse date " . $_[1]) unless $_[1] =~ m/(\d+)-(\d+)-(\d+)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1] =~ /(\d+)-(\d+)-(\d+)/ 0 0 0
358 0 $dt = DateTime->new(
359 year => $1,
360 month => $2,
361 day => $3
362 );
363 }
364 0 return $dt;
365 }
366 0 ▶sub validate($) { return scalar($_[1] =~ m/(\d+-\d+-\d+)T?(\d+:\d+:\d+)/); }
Subroutine validate: not called CC=1 SCAR=6.9
367  
368 sub generate($) {
369 1 ▶ my %hash = @{$_[0]->{arguments}};
Subroutine generate: called CC=3 SCAR=11.3
370 1 ▶ $hash{min} = '2010-01-01 00:00:00' unless $hash{min};
Branch: 1 branch
BranchTrueFalseTotal
unless $hash{"min"} 0 1 1
371 1 ▶ $hash{max} = 'now' unless $hash{max};
Branch: 1 branch
BranchTrueFalseTotal
unless $hash{"max"} 0 1 1
372 1 return ::rand_datetime(%hash);
373 }
374 0 ▶sub data_type { return WWW::Shopify::Field::TYPE_QUANTITATIVE; }
Subroutine data_type: not called CC=1 SCAR=6.9
375  
376 # Freeform datastructure. Meaning we convert it to a JSON hash, but we don't do any further processing at all.
377 package WWW::Shopify::Field::Freeform;
378 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
379 0 ▶sub sql_type { return "text"; }
Subroutine sql_type: not called CC=1 SCAR=6.9
380 0 ▶sub generate { return {}; }
Subroutine generate: not called CC=1 SCAR=6.9
381 0 ▶sub data_type { return WWW::Shopify::Field::TYPE_QUALITATIVE; }
Subroutine data_type: not called CC=1 SCAR=6.9
382 0 ▶sub validate { return !defined $_[1] || (ref($_[1]) && ref($_[1]) eq "HASH"); }
Subroutine validate: not called CC=3 SCAR=24.8
Condition0%0/6
!defined($_[1]) || ref $_[1] && ref $_[1] eq 'HASH'
l!l&&r!l&&!r
000
ref $_[1] and ref $_[1] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/3
!defined($_[1]) || ref $_[1] && ref $_[1] eq 'HASH'
!defined($_[1]) ref $_[1] ref $_[1] eq "HASH"
Truth table0%0/4
not(A) || B and C
A= !defined($_[1])B= ref $_[1]C= ref $_[1] eq "HASH"
ABCresult
1XX1
0111
00X0
0100
383 0 ▶sub to_shopify { return $_[1]; }
Subroutine to_shopify: not called CC=1 SCAR=6.9
384 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
385 0 ▶sub from_shopify { print STDERR Dumper($_[1]); return $_[1]; }
Subroutine from_shopify: not called CC=1 SCAR=6.9
386  
387 1 1;
« blib/lib/WWW/Shopify/Model/Shop.pm ↑ Summary blib/lib/WWW/Shopify/Exception.pm »