Shopify/Field.pm

filter: Statementstmt 39.2% 106 / 270 Branchbran 0.0% 0 / 76 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 26.3% 34 / 129 Podpod 0.0% 0 / 21 totaltotal 26.0% 140 / 538 CC 48 SCAR 22.9
CC
48
Cov
28%
from_shopify
90.0
validate
20.0
from_shopify
20.0
CRAP 9.9
« Shopify/Exception.pm ↑ Summary Shopify/URLHandler/Queued.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 0 ▶sub new($) {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
26 0 my $package = shift;
27 0 my $calling_package = caller(0);
28 0 return bless {
29 arguments => [@_],
30 name => undef,
31 owner => $calling_package
32 }, $package;
33 }
34 0 ▶sub name { $_[0]->{name} = $_[1] if defined $_[1]; return $_[0]->{name}; }
Subroutine name: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[1] 0 0 0
35 0 ▶sub camelCase {
Subroutine camelCase: not called CC=1 SCAR=6.9
Pod undocumented
36 0 my ($self) = @_;
37 0 my ($name) = $self->name;
38 0 return lcfirst(join("", map { ucfirst($_) } split(/_/, lc($name))));
39 }
40 0 ▶sub sql_type($) { die ref($_[0]); }
Subroutine sql_type: not called CC=1 SCAR=6.9
Pod undocumented
41 0 ▶sub is_relation { return undef; }
Subroutine is_relation: not called CC=1 SCAR=6.9
Pod undocumented
42 0 ▶sub is_qualifier { return undef; }
Subroutine is_qualifier: not called CC=1 SCAR=6.9
Pod undocumented
43 0 ▶sub qualifier { return undef; }
Subroutine qualifier: not called CC=1 SCAR=6.9
Pod undocumented
44 0 ▶sub to_shopify($$) { return $_[1]; }
Subroutine to_shopify: not called CC=1 SCAR=6.9
Pod undocumented
45 0 ▶sub from_shopify($$) { return $_[1]; }
Subroutine from_shopify: not called CC=1 SCAR=6.9
Pod undocumented
46 0 ▶sub generate($) { die "Can't generate $_[0]"; }
Subroutine generate: not called CC=1 SCAR=6.9
Pod undocumented
47 0 ▶sub validate($) { die "Can't validate $_[0]"; }
Subroutine validate: not called CC=1 SCAR=6.9
Pod undocumented
48 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
49  
50 0 ▶sub is_db_belongs_to { return undef; }
Subroutine is_db_belongs_to: not called CC=1 SCAR=6.9
Pod undocumented
51 0 ▶sub is_db_has_many { return undef; }
Subroutine is_db_has_many: not called CC=1 SCAR=6.9
Pod undocumented
52 0 ▶sub is_db_many_many { return undef; }
Subroutine is_db_many_many: not called CC=1 SCAR=6.9
Pod undocumented
53 0 ▶sub is_db_has_one { return undef; }
Subroutine is_db_has_one: not called CC=1 SCAR=6.9
Pod undocumented
54  
55 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
56 1 TYPE_QUANTITATIVE => 0,
57 TYPE_QUALITATIVE => 1,
58 TYPE_BOOLEAN => 2
59 1 };
60  
61 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
62 # No order, no set distance (E.G. Telephone Numbers)
63 1 SET_NOMINAL => 0,
64 # No set distance between values.
65 SET_ORDINAL => 1,
66 # Distinguishable distance between values. (E.G. Real Numbers)
67 SET_CARDINAL => 2
68 1 };
69  
70 1 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
71 1 our @EXPORT_OK = qw(TYPE_QUANTITATIVE TYPE_QUALITATIVE TYPE_BOOLEAN SET_NOMINAL SET_ORDINAL SET_CARDINAL);
72  
73 0 ▶sub data_type { return TYPE_QUALITATIVE; }
Subroutine data_type: not called CC=1 SCAR=6.9
Pod undocumented
74 0 ▶sub is_quantitative { return $_[0]->data_type == TYPE_QUANTITATIVE; }
Subroutine is_quantitative: not called CC=1 SCAR=6.9
Pod undocumented
75 0 ▶sub is_qualitative { return $_[0]->data_type == TYPE_QUALITATIVE; }
Subroutine is_qualitative: not called CC=1 SCAR=6.9
Pod undocumented
76 0 ▶sub is_boolean { return $_[0]->data_type == TYPE_BOOLEAN; }
Subroutine is_boolean: not called CC=1 SCAR=6.9
Pod undocumented
77 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
78  
79 package WWW::Shopify::Field::Hook;
80 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
81 0 ▶sub new($) { return bless { internal => $_[1], qualifier => $_[2] }, $_[0]; }
Subroutine new: not called CC=1 SCAR=6.9
82 0 ▶sub sql_type($) { return shift->{internal}->sql_type(@_); }
Subroutine sql_type: not called CC=1 SCAR=6.9
83 0 ▶sub is_relation { return shift->{internal}->is_relation(@_); }
Subroutine is_relation: not called CC=1 SCAR=6.9
84 0 ▶sub to_shopify($$) { return shift->{internal}->to_shopify(@_); }
Subroutine to_shopify: not called CC=1 SCAR=6.9
85 0 ▶sub from_shopify($$) { return shift->{internal}->from_shopify(@_); }
Subroutine from_shopify: not called CC=1 SCAR=6.9
86 0 ▶sub generate($) { return shift->{internal}->generate(@_); }
Subroutine generate: not called CC=1 SCAR=6.9
87 0 ▶sub relation($) { return shift->{internal}->relation(@_); }
Subroutine relation: not called CC=1 SCAR=6.9
88 0 ▶sub is_many { return shift->{internal}->is_many(@_); }
Subroutine is_many: not called CC=1 SCAR=6.9
89 0 ▶sub is_one { return shift->{internal}->is_one(@_); }
Subroutine is_one: not called CC=1 SCAR=6.9
90 0 ▶sub is_own { return shift->{internal}->is_own(@_); }
Subroutine is_own: not called CC=1 SCAR=6.9
91 0 ▶sub is_reference { return shift->{internal}->is_reference(@_); }
Subroutine is_reference: not called CC=1 SCAR=6.9
92  
93 package WWW::Shopify::Field::Int;
94 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
95 1 ▶use String::Numeric qw(is_int);
Subroutine BEGIN: called CC=1 SCAR=0.0
96 0 ▶sub sql_type { return "int"; }
Subroutine sql_type: not called CC=1 SCAR=6.9
97 0 ▶sub generate($) {
Subroutine generate: not called CC=3 SCAR=24.8
98 0 ▶ return int(rand(10000)) if (int(@{$_[0]->{arguments}}) == 0);
Branch: 1 branch
BranchTrueFalseTotal
if int @{$_[0]{"arguments"};} == 0 0 0 0
99 0 ▶ return $_[0]->{arguments}->[0] if (int(@{$_[0]->{arguments}}) == 1);
Branch: 1 branch
BranchTrueFalseTotal
if int @{$_[0]{"arguments"};} == 1 0 0 0
100 0 return int(rand($_[0]->{arguments}->[1] - $_[0]->{arguments}->[0] + 1) + $_[0]->{arguments}->[0]);
101 }
102 0 ▶sub data_type { return WWW::Shopify::Field::TYPE_QUANTITATIVE; }
Subroutine data_type: not called CC=1 SCAR=6.9
103 0 ▶sub validate($$) { return is_int($_[1]); }
Subroutine validate: not called CC=1 SCAR=6.9
104  
105 package WWW::Shopify::Field::BigInt;
106 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
107 1 ▶use String::Numeric qw(is_int);
Subroutine BEGIN: called CC=1 SCAR=0.0
108 0 ▶sub sql_type { return "bigint"; }
Subroutine sql_type: not called CC=1 SCAR=6.9
109 0 ▶sub generate($) {
Subroutine generate: not called CC=3 SCAR=24.8
110 0 ▶ return int(rand(10000000)) if (int(@{$_[0]->{arguments}}) == 0);
Branch: 1 branch
BranchTrueFalseTotal
if int @{$_[0]{"arguments"};} == 0 0 0 0
111 0 ▶ return $_[0]->{arguments}->[0] if (int(@{$_[0]->{arguments}}) == 1);
Branch: 1 branch
BranchTrueFalseTotal
if int @{$_[0]{"arguments"};} == 1 0 0 0
112 0 return int(rand($_[0]->{arguments}->[1] - $_[0]->{arguments}->[0] + 1) + $_[0]->{arguments}->[0]);
113 }
114 0 ▶sub data_type { return WWW::Shopify::Field::TYPE_QUANTITATIVE; }
Subroutine data_type: not called CC=1 SCAR=6.9
115 0 ▶sub validate { return is_int($_[1]); }
Subroutine validate: not called CC=1 SCAR=6.9
116  
117 package WWW::Shopify::Field::Boolean;
118 1 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
119 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
120 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
121 0 ▶sub sql_type { return "bool"; }
Subroutine sql_type: not called CC=1 SCAR=6.9
122 0 ▶sub generate { return (rand() < 0.5); }
Subroutine generate: not called CC=1 SCAR=6.9
123 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
124 0 ▶sub data_type { return WWW::Shopify::Field::TYPE_BOOLEAN; }
Subroutine data_type: not called CC=1 SCAR=6.9
125 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
126 0 ▶sub from_shopify { return $_[1] ? 1 : 0; }
Subroutine from_shopify: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 0 0 0
127  
128 package WWW::Shopify::Field::Float;
129 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
130 1 ▶use String::Numeric qw(is_float);
Subroutine BEGIN: called CC=1 SCAR=0.0
131 0 ▶sub sql_type { return "float"; }
Subroutine sql_type: not called CC=1 SCAR=6.9
132 0 ▶sub generate($) {
Subroutine generate: not called CC=3 SCAR=24.8
133 0 ▶ return rand() * 10000.0 if (int(@{$_[0]->{arguments}}) == 0);
Branch: 1 branch
BranchTrueFalseTotal
if int @{$_[0]{"arguments"};} == 0 0 0 0
134 0 ▶ return $_[0]->{arguments}->[0] if (int(@{$_[0]->{arguments}}) == 1);
Branch: 1 branch
BranchTrueFalseTotal
if int @{$_[0]{"arguments"};} == 1 0 0 0
135 0 return rand($_[0]->{arguments}->[1] - $_[0]->{arguments}->[0] + 1) + $_[0]->{arguments}->[0];
136 }
137 0 ▶sub data_type { return WWW::Shopify::Field::TYPE_QUANTITATIVE; }
Subroutine data_type: not called CC=1 SCAR=6.9
138 0 ▶sub validate($$) { return is_float($_[1]); }
Subroutine validate: not called CC=1 SCAR=6.9
139  
140 package WWW::Shopify::Field::Timestamp;
141 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
142 1 ▶use String::Numeric qw(is_int);
Subroutine BEGIN: called CC=1 SCAR=0.0
143 0 ▶sub sql_type { return "bigint"; }
Subroutine sql_type: not called CC=1 SCAR=6.9
144 0 ▶sub generate($) {
Subroutine generate: not called CC=3 SCAR=24.8
145 0 ▶ return int(rand(10000000)) if (int(@{$_[0]->{arguments}}) == 0);
Branch: 1 branch
BranchTrueFalseTotal
if int @{$_[0]{"arguments"};} == 0 0 0 0
146 0 ▶ return $_[0]->{arguments}->[0] if (int(@{$_[0]->{arguments}}) == 1);
Branch: 1 branch
BranchTrueFalseTotal
if int @{$_[0]{"arguments"};} == 1 0 0 0
147 0 return int(rand($_[0]->{arguments}->[1] - $_[0]->{arguments}->[0] + 1) + $_[0]->{arguments}->[0]);
148 }
149 0 ▶sub data_type { return WWW::Shopify::Field::TYPE_QUANTITATIVE; }
Subroutine data_type: not called CC=1 SCAR=6.9
150 0 ▶sub validate { return is_int($_[1]); }
Subroutine validate: not called CC=1 SCAR=6.9
151  
152 package WWW::Shopify::Field::Timezone;
153 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
154 0 ▶sub sql_type { return "varchar(255)"; }
Subroutine sql_type: not called CC=1 SCAR=6.9
155  
156 1 my %from_shopify_timezones = (
157 "(GMT-05:00) Eastern Time (US & Canada)" => "America/New_York",
158 "(GMT-11:00) International Date Line West" => "-1100",
159 "(GMT-11:00) Midway Island" => "Pacific/Midway",
160 "(GMT-11:00) American Samoa" => "Pacific/Pago_Pago",
161 "(GMT-10:00) Hawaii" => "Pacific/Honolulu",
162 "(GMT-09:00) Alaska" => "America/Anchorage",
163 "(GMT-08:00) Pacific Time (US & Canada)" => "PST8PDT",
164 "(GMT-08:00) Tijuana" => "America/Tijuana",
165 "(GMT-07:00) Mountain Time (US & Canada)" => "MST7MDT",
166 "(GMT-07:00) Arizona" => "MST",
167 "(GMT-07:00) Chihuahua" => "America/Chihuahua",
168 "(GMT-07:00) Mazatlan" => "MST",
169 "(GMT-06:00) Central Time (US & Canada)" => "CST6CDT",
170 "(GMT-06:00) Saskatchewan" => "-0600",
171 "(GMT-06:00) Guadalajara" => "CST6CDT",
172 "(GMT-06:00) Mexico City" => "CST6CDT",
173 "(GMT-06:00) Monterrey" => "America/Monterrey",
174 "(GMT-06:00) Central America" => "CST6CDT",
175 "(GMT-05:00) Indiana (East)" => "EST5EDT",
176 "(GMT-05:00) Bogota" => "America/Bogota",
177 "(GMT-05:00) Lima" => "America/Lima",
178 "(GMT-05:00) Quito" => "-0500",
179 "(GMT-04:00) Atlantic Time (Canada)" => "America/Halifax",
180 "(GMT-04:30) Caracas" => "America/Caracas",
181 "(GMT-04:00) La Paz" => "-04:00",
182 "(GMT-04:00) Santiago" => "America/Santiago",
183 "(GMT-03:30) Newfoundland" => "America/La_Paz",
184 "(GMT-03:00) Brasilia" => "America/Sao_Paulo",
185 "(GMT-03:00) Buenos Aires" => "America/Argentina/Buenos_Aires",
186 "(GMT-04:00) Georgetown" => "America/Guyana",
187 "(GMT-03:00) Greenland" => "-0300",
188 "(GMT-02:00) Mid-Atlantic" => "-0200",
189 "(GMT-01:00) Azores" => "Atlantic/Azores",
190 "(GMT-01:00) Cape Verde Is." => "Atlantic/Cape_Verde",
191 "(GMT+00:00) Dublin" => "Europe/Dublin",
192 "(GMT+00:00) Edinburgh" => "Europe/London",
193 "(GMT+00:00) Lisbon" => "Europe/Lisbon",
194 "(GMT+00:00) London" => "Europe/London",
195 "(GMT+00:00) Casablanca" => "Africa/Casablanca",
196 "(GMT+00:00) Monrovia" => "Africa/Monrovia",
197 "(GMT+00:00) UTC" => "UTC",
198 "(GMT+01:00) Belgrade" => "Europe/Belgrade",
199 "(GMT+01:00) Bratislava" => "Europe/Bratislava",
200 "(GMT+01:00) Budapest" => "Europe/Budapest",
201 "(GMT+01:00) Ljubljana" => "Europe/Ljubljana",
202 "(GMT+01:00) Prague" => "Europe/Prague",
203 "(GMT+01:00) Sarajevo" => "Europe/Sarajevo",
204 "(GMT+01:00) Skopje" => "Europe/Skopje",
205 "(GMT+01:00) Warsaw" => "Europe/Warsaw",
206 "(GMT+01:00) Zagreb" => "Europe/Zagreb",
207 "(GMT+01:00) Brussels" => "Europe/Brussels",
208 "(GMT+01:00) Copenhagen" => "Europe/Copenhagen",
209 "(GMT+01:00) Madrid" => "Europe/Madrid",
210 "(GMT+01:00) Paris" => "Europe/Paris",
211 "(GMT+01:00) Amsterdam" => "Europe/Amsterdam",
212 "(GMT+01:00) Berlin" => "Europe/Berlin",
213 "(GMT+01:00) Bern" => "Europe/Zurich",
214 "(GMT+01:00) Rome" => "Europe/Rome",
215 "(GMT+01:00) Stockholm" => "Europe/Stockholm",
216 "(GMT+01:00) Vienna" => "Europe/Vienna",
217 "(GMT+01:00) West Central Africa" => "+0100",
218 "(GMT+02:00) Bucharest" => "Europe/Bucharest",
219 "(GMT+02:00) Cairo" => "Africa/Cairo",
220 "(GMT+02:00) Helsinki" => "Europe/Helsinki",
221 "(GMT+02:00) Kyiv" => "Europe/Kiev",
222 "(GMT+02:00) Riga" => "Europe/Riga",
223 "(GMT+02:00) Sofia" => "Europe/Sofia",
224 "(GMT+02:00) Tallinn" => "Europe/Tallinn",
225 "(GMT+02:00) Vilnius" => "Europe/Vilnius",
226 "(GMT+02:00) Athens" => "Europe/Athens",
227 "(GMT+02:00) Istanbul" => "Europe/Istanbul",
228 "(GMT+03:00) Minsk" => "Europe/Minsk",
229 "(GMT+02:00) Jerusalem" => "Asia/Jerusalem",
230 "(GMT+02:00) Harare" => "Africa/Harare",
231 "(GMT+02:00) Pretoria" => "Africa/Maseru",
232 "(GMT+04:00) Moscow" => "Europe/Moscow",
233 "(GMT+04:00) St. Petersburg" => "Europe/Moscow",
234 "(GMT+04:00) Volgograd" => "Europe/Volgograd",
235 "(GMT+03:00) Kuwait" => "Asia/Kuwait",
236 "(GMT+03:00) Riyadh" => "Asia/Riyadh",
237 "(GMT+03:00) Nairobi" => "Africa/Nairobi",
238 "(GMT+03:00) Baghdad" => "Asia/Baghdad",
239 "(GMT+03:30) Tehran" => "Asia/Tehran",
240 "(GMT+04:00) Abu Dhabi" => "+0400",
241 "(GMT+04:00) Muscat" => "Asia/Muscat",
242 "(GMT+04:00) Baku" => "Asia/Baku",
243 "(GMT+04:00) Tbilisi" => "Asia/Tbilisi",
244 "(GMT+04:00) Yerevan" => "Asia/Yerevan",
245 "(GMT+04:30) Kabul" => "Asia/Kabul",
246 "(GMT+06:00) Ekaterinburg" => "Asia/Yekaterinburg",
247 "(GMT+05:00) Islamabad" => "+05:00",
248 "(GMT+05:00) Karachi" => "Asia/Karachi",
249 "(GMT+05:00) Tashkent" => "Asia/Tashkent",
250 "(GMT+05:30) Chennai" => "+05:30",
251 "(GMT+05:30) Kolkata" => "Asia/Kolkata",
252 "(GMT+05:30) Mumbai" => "+05:30",
253 "(GMT+05:30) New Delhi" => "+05:30",
254 "(GMT+05:45) Kathmandu" => "Asia/Kathmandu",
255 "(GMT+06:00) Astana" => "Asia/Thimphu",
256 "(GMT+06:00) Dhaka" => "Asia/Dhaka",
257 "(GMT+05:30) Sri Jayawardenepura" => "+0530",
258 "(GMT+06:00) Almaty" => "Asia/Almaty",
259 "(GMT+07:00) Novosibirsk" => "Asia/Novosibirsk",
260 "(GMT+06:30) Rangoon" => "Asia/Rangoon",
261 "(GMT+07:00) Bangkok" => "Asia/Bangkok",
262 "(GMT+07:00) Hanoi" => "+0700",
263 "(GMT+07:00) Jakarta" => "Asia/Jakarta",
264 "(GMT+08:00) Krasnoyarsk" => "Asia/Krasnoyarsk",
265 "(GMT+08:00) Beijing" => "Asia/Shanghai",
266 "(GMT+08:00) Chongqing" => "Asia/Chongqing",
267 "(GMT+08:00) Hong Kong" => "Asia/Hong_Kong",
268 "(GMT+08:00) Urumqi" => "Asia/Urumqi",
269 "(GMT+08:00) Kuala Lumpur" => "Asia/Kuala_Lumpur",
270 "(GMT+08:00) Singapore" => "Asia/Singapore",
271 "(GMT+08:00) Taipei" => "Asia/Taipei",
272 "(GMT+08:00) Perth" => "Australia/Perth",
273 "(GMT+09:00) Irkutsk" => "Asia/Irkutsk",
274 "(GMT+08:00) Ulaan Bataar" => "Asia/Ulaanbaatar",
275 "(GMT+09:00) Seoul" => "Asia/Seoul",
276 "(GMT+09:00) Osaka" => "Asia/Tokyo",
277 "(GMT+09:00) Sapporo" => "Asia/Tokyo",
278 "(GMT+09:00) Tokyo" => "Asia/Tokyo",
279 "(GMT+10:00) Yakutsk" => "Asia/Yakutsk",
280 "(GMT+09:30) Darwin" => "Australia/Darwin",
281 "(GMT+09:30) Adelaide" => "Australia/Adelaide",
282 "(GMT+10:00) Canberra" => "Australia/Canberra",
283 "(GMT+10:00) Melbourne" => "Australia/Melbourne",
284 "(GMT+10:00) Sydney" => "Australia/Sydney",
285 "(GMT+10:00) Brisbane" => "Australia/Brisbane",
286 "(GMT+10:00) Hobart" => "Australia/Hobart",
287 "(GMT+11:00) Vladivostok" => "Asia/Vladivostok",
288 "(GMT+10:00) Guam" => "Pacific/Guam",
289 "(GMT+10:00) Port Moresby" => "Pacific/Port_Moresby",
290 "(GMT+12:00) Magadan" => "Asia/Magadan",
291 "(GMT+12:00) Solomon Is." => "+1100",
292 "(GMT+11:00) New Caledonia" => "+1100",
293 "(GMT+12:00) Fiji" => "Pacific/Fiji",
294 "(GMT+12:00) Kamchatka" => "Asia/Kamchatka",
295 "(GMT+12:00) Marshall Is." => "Pacific/Majuro",
296 "(GMT+12:00) Auckland" => "Pacific/Auckland",
297 "(GMT+12:00) Pacific/Auckland" => "Pacific/Auckland",
298 "(GMT+12:00) Wellington" => "Pacific/Auckland",
299 "(GMT+13:00) Nuku'alofa" => "Pacific/Tongatapu",
300 "(GMT+13:00) Tokelau Is." => "Pacific/Fakaofo",
301 "(GMT+13:00) Samoa" => "Pacific/Apia",
302
303 "(GMT-10:00) Pacific/Honolulu" => "Pacific/Honolulu",
304 "(GMT-08:00) America/Los_Angeles" => "America/Los_Angeles",
305 "(GMT-08:00) America/Vancouver" => "America/Vancouver",
306 "(GMT-07:00) America/Denver" => "America/Denver",
307 "(GMT-07:00) America/Phoenix" => "America/Phoenix",
308 "(GMT-06:00) America/Chicago" => "America/Chicago",
309 "(GMT-06:00) America/Winnipeg" => "America/Winnipeg",
310 "(GMT-05:00) America/New_York" => "America/New_York",
311 "(GMT-05:00) America/Toronto" => "America/Toronto",
312 "(GMT-05:00) America/Montreal" => "America/Montreal",
313 "(GMT-03:00) America/Montevideo" => "America/Montevideo",
314 "(GMT+00:00) Europe/London" => "Europe/London",
315 "(GMT+01:00) Europe/Madrid" => "Europe/Madrid",
316 "(GMT+01:00) Europe/Oslo" => "Europe/Oslo",
317 "(GMT+01:00) Europe/Stockholm" => "Europe/Stockholm",
318 "(GMT+05:00) Asia/Karachi" => "Asia/Karachi",
319 "(GMT+05:30) Asia/Calcutta" => "Asia/Calcutta",
320 "(GMT+09:30) Australia/South" => "Australia/South",
321 "(GMT+10:00) Australia/NSW" => "Australia/NSW",
322 "(GMT+10:00) Australia/Queensland" => "Australia/Queensland",
323 "(GMT+10:00) Australia/Victoria" => "Australia/Victoria",
324
325 "(GMT-03:00) Montevideo" => "America/Montevideo",
326 "(GMT+02:00) Kaliningrad" => "Europe/Kaliningrad",
327 "(GMT+03:00) Moscow" => "Europe/Moscow",
328 "(GMT+03:00) St. Petersburg" => "Europe/Moscow",
329 "(GMT+03:00) Volgograd" => "Europe/Volgograd",
330 "(GMT+04:00) Samara" => "Europe/Samara",
331 "(GMT+05:00) Ekaterinburg" => "Asia/Yekaterinburg",
332 "(GMT+06:00) Novosibirsk" => "Asia/Novosibirsk",
333 "(GMT+06:00) Urumqi" => "Asia/Urumqi",
334 "(GMT+07:00) Krasnoyarsk" => "Asia/Krasnoyarsk",
335 "(GMT+08:00) Irkutsk" => "Asia/Irkutsk",
336 "(GMT+08:00) Ulaanbaatar" => "Asia/Ulaanbaatar",
337 "(GMT+09:00) Yakutsk" => "Asia/Yakutsk",
338 "(GMT+10:00) Magadan" => "Asia/Magadan",
339 "(GMT+10:00) Vladivostok" => "Asia/Vladivostok",
340 "(GMT+11:00) Solomon Is." => "Pacific/Guadalcanal",
341 "(GMT+11:00) Srednekolymsk" => "Asia/Srednekolymsk",
342 "(GMT+12:45) Chatham Is." => "Pacific/Chatham"
343 );
344 1 my %to_shopify_timezones = reverse(%from_shopify_timezones);
345  
346 0 ▶sub timezone_mapping { return \%to_shopify_timezones; }
Subroutine timezone_mapping: not called CC=1 SCAR=6.9
347 0 ▶sub shopify_timezones { return keys(%from_shopify_timezones); }
Subroutine shopify_timezones: not called CC=1 SCAR=6.9
348  
349 0 ▶sub to_shopify {
Subroutine to_shopify: not called CC=3 SCAR=24.8
350 0 my $dttz = $_[1];
351 0 ▶ return undef unless $dttz;
Branch: 1 branch
BranchTrueFalseTotal
unless $dttz 0 0 0
352 0 my $mapping = $to_shopify_timezones{$dttz->name};
353 0 ▶ $mapping = "(GMT+00:00) UTC" unless $mapping;
Branch: 1 branch
BranchTrueFalseTotal
unless $mapping 0 0 0
354 0 return $mapping;
355 }
356  
357 0 ▶sub from_shopify {
Subroutine from_shopify: not called CC=3 SCAR=24.8
358 0 my $dttz = $_[1];
359 0 ▶ return undef unless $dttz;
Branch: 1 branch
BranchTrueFalseTotal
unless $dttz 0 0 0
360 0 my $mapping = $from_shopify_timezones{$dttz};
361 0 ▶ $mapping = "UTC" unless $mapping;
Branch: 1 branch
BranchTrueFalseTotal
unless $mapping 0 0 0
362 0 return DateTime::TimeZone->new(name => $mapping);
363 }
364  
365 0 ▶sub generate {
Subroutine generate: not called CC=1 SCAR=6.9
366 0 my @timezones = keys(%from_shopify_timezones);
367 0 return $timezones[int(rand(@timezones))];
368 }
369  
370 package WWW::Shopify::Field::Timezone::IANA;
371 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
372  
373 0 ▶sub sql_type { return "varchar(255)"; }
Subroutine sql_type: not called CC=1 SCAR=6.9
374 0 ▶sub to_shopify {
Subroutine to_shopify: not called CC=2 SCAR=17.9
375 0 my $dttz = $_[1];
376 0 ▶ return undef unless $dttz;
Branch: 1 branch
BranchTrueFalseTotal
unless $dttz 0 0 0
377 0 return $dttz->name;
378 }
379  
380 0 ▶sub from_shopify {
Subroutine from_shopify: not called CC=4 SCAR=30.0
381 0 my $dttz = $_[1];
382 0 ▶ return undef unless $dttz;
Branch: 1 branch
BranchTrueFalseTotal
unless $dttz 0 0 0
383 0 ▶ return $dttz if ref($dttz) && ref($dttz) =~ m/DateTime::TimeZone/;
Branch: 1 branch
BranchTrueFalseTotal
if ref $dttz and ref($dttz) =~ /DateTime::TimeZone/ 0 0 0
Condition0%0/3
ref $dttz and ref($dttz) =~ /DateTime::TimeZone/
!ll&&!rl&&r
000
MC/DC0%0/2
ref $dttz and ref($dttz) =~ /DateTime::TimeZone/
ref $dttz ref($dttz) =~ /DateTime::TimeZone/
Truth table0%0/3
A and B
A= ref $dttzB= ref($dttz) =~ /DateTime::TimeZone/
ABresult
0X0
100
111
384 0 return DateTime::TimeZone->new(name => $dttz);
385 }
386  
387 0 ▶sub generate {
Subroutine generate: not called CC=1 SCAR=6.9
388 0 my @timezones = values(%WWW::Shopify::Field::Timezone::from_shopify_timezones);
389 0 return $timezones[int(rand(@timezones))];
390 }
391  
392  
393  
394 package WWW::Shopify::Field::Currency;
395 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
396 0 ▶sub sql_type { return "varchar(255)"; }
Subroutine sql_type: not called CC=1 SCAR=6.9
397 0 ▶sub generate($) { return rand() < 0.5 ? "USD" : "CAD"; }
Subroutine generate: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
rand() < 0.5 ? : 0 0 0
398  
399 package WWW::Shopify::Field::Money;
400 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
401 1 ▶use String::Numeric qw(is_float);
Subroutine BEGIN: called CC=1 SCAR=0.0
402 0 ▶sub sql_type { return "decimal(16,2)"; }
Subroutine sql_type: not called CC=1 SCAR=6.9
403 0 ▶sub generate($) { return sprintf("%.2f", rand(500)); }
Subroutine generate: not called CC=1 SCAR=6.9
404 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
405 0 ▶sub data_type { return WWW::Shopify::Field::TYPE_QUANTITATIVE; }
Subroutine data_type: not called CC=1 SCAR=6.9
406 0 ▶sub to_shopify { defined $_[1] ? sprintf('%.2f', $_[1]) : undef; }
Subroutine to_shopify: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 0 0 0
407  
408 package WWW::Shopify::Field::Money::USD;
409 1 ▶use parent -norequire, 'WWW::Shopify::Field::Money';
Subroutine BEGIN: called CC=1 SCAR=0.0
410  
411 package WWW::Shopify::Field::Date;
412 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
413 1 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
414 0 ▶sub sql_type { return 'datetime'; }
Subroutine sql_type: not called CC=1 SCAR=6.9
415 0 ▶sub to_shopify {
Subroutine to_shopify: not called CC=4 SCAR=30.0
416 0 my $dt = $_[1];
417 0 ▶ return undef unless $dt;
Branch: 1 branch
BranchTrueFalseTotal
unless $dt 0 0 0
418 0 ▶ if (ref($dt) eq "DateTime") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dt eq "DateTime") 0 0 0
419 0 my $t = $dt->strftime('%Y-%m-%dT%H:%M:%S%z');
420 0 $t =~ s/(\d\d)$/:$1/;
421 0 return $t;
422 }
423 0 ▶ die new WWW::Shopify::Exception($_[0]->name . ": " . $dt) unless $dt =~ m/([\d-]+)\s*T?\s*([\d:]+)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $dt =~ /([\d-]+)\s*T?\s*([\d:]+)/ 0 0 0
424 0 return "$1T$2";
425 }
426 0 ▶sub from_shopify {
Subroutine from_shopify: not called CC=9 SCAR=45.0
427 0 my $dt;
428 0 ▶ return undef unless $_[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1] 0 0 0
429 0 my @abbrvs = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
430 0 my $abbrvs_reg = join("|", @abbrvs);
431 0 ▶ if ($_[1] =~ m/(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)([+-]\d+):(\d+)/) {
Branch: 6 branches
BranchTrueFalseTotal
if ($_[1] =~ /(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)([+-]\d+):(\d+)/) { } 0 0 0
elsif ($_[1] =~ /(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)/) { } 0 0 0
elsif ($_[1] =~ /(\d+):(\d+):(\d+) ($abbrvs_reg) (\d+), (\d+)/) { } 0 0 0
elsif ($_[1] =~ /(\d+)\-($abbrvs_reg)\-(\d+) (\d+):(\d+):(\d+)/) { } 0 0 0
elsif ($_[1] =~ /^(\d\d)(\d\d)(\d\d\d\d)(\d\d)(\d\d)(\d\d)$/) { } 0 0 0
elsif ($_[1] =~ /^(\d+)$/) { } 0 0 0
432 0 $dt = DateTime->new(
433 year => $1,
434 month => $2,
435 day => $3,
436 hour => $4,
437 minute => $5,
438 second => $6,
439 time_zone => $7 . $8,
440 );
441 }
442 elsif ($_[1] =~ m/(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)/) {
443 0 $dt = DateTime->new(
444 year => $1,
445 month => $2,
446 day => $3,
447 hour => $4,
448 minute => $5,
449 second => $6,
450 );
451 }
452 elsif ($_[1] =~ m/(\d+):(\d+):(\d+) ($abbrvs_reg) (\d+), (\d+)/) {
453 0 my %types = map { $abbrvs[$_] => ($_+1) } 0..$#abbrvs;
454 $dt = DateTime->new(
455 hour => $1,
456 minute => $2,
457 second => $3,
458
459 year => $6,
460 0 month => $types{$4},
461 day => $5,
462 );
463 }
464 elsif ($_[1] =~ m/(\d+)\-($abbrvs_reg)\-(\d+) (\d+):(\d+):(\d+)/) {
465 0 my %types = map { $abbrvs[$_] => ($_+1) } 0..$#abbrvs;
466 $dt = DateTime->new(
467 day => $1,
468 0 month => $types{$2},
469 year => $3,
470
471 hour => $4,
472 minute => $5,
473 second => $6,
474 );
475 }
476 elsif ($_[1] =~ m/^(\d\d)(\d\d)(\d\d\d\d)(\d\d)(\d\d)(\d\d)$/) {
477 0 $dt = DateTime->new(
478 hour => $4,
479 minute => $5,
480 second => $6,
481  
482 year => $3,
483 month => $2,
484 day => $1,
485 );
486 } elsif ($_[1] =~ m/^(\d+)$/) {
487 0 $dt = DateTime->from_epoch(epoch => $1);
488 } else {
489 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
490 0 $dt = DateTime->new(
491 year => $1,
492 month => $2,
493 day => $3
494 );
495 }
496 0 return $dt;
497 }
498 0 ▶sub validate($) { return scalar($_[1] =~ m/(\d+-\d+-\d+)T?(\d+:\d+:\d+)/); }
Subroutine validate: not called CC=1 SCAR=6.9
499  
500 0 ▶sub generate($) {
Subroutine generate: not called CC=4 SCAR=30.0
501 0 ▶ my %hash = $_[1] ? %{$_[1]} : @{$_[0]->{arguments}};
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 0 0 0
502 0 ▶ $hash{min} = '2010-01-01 00:00:00' unless $hash{min};
Branch: 1 branch
BranchTrueFalseTotal
unless $hash{"min"} 0 0 0
503 0 ▶ $hash{max} = 'now' unless $hash{max};
Branch: 1 branch
BranchTrueFalseTotal
unless $hash{"max"} 0 0 0
504 0 my $date = ::rand_datetime(%hash);
505 0 return $date;
506 }
507 0 ▶sub data_type { return WWW::Shopify::Field::TYPE_QUANTITATIVE; }
Subroutine data_type: not called CC=1 SCAR=6.9
508  
509 # Freeform datastructure. Meaning we convert it to a JSON hash, but we don't do any further processing at all.
510 package WWW::Shopify::Field::Freeform;
511 1 ▶use parent 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
512 0 ▶sub sql_type { return "text"; }
Subroutine sql_type: not called CC=1 SCAR=6.9
513 0 ▶sub generate { return {}; }
Subroutine generate: not called CC=1 SCAR=6.9
514 0 ▶sub data_type { return WWW::Shopify::Field::TYPE_QUALITATIVE; }
Subroutine data_type: not called CC=1 SCAR=6.9
515 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
516 0 ▶sub to_shopify { return $_[1]; }
Subroutine to_shopify: not called CC=1 SCAR=6.9
517 0 ▶sub from_shopify { return $_[1]; }
Subroutine from_shopify: not called CC=1 SCAR=6.9
518  
519 package WWW::Shopify::Field::Freeform::Array;
520 1 ▶use base 'WWW::Shopify::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
521 0 ▶sub sql_type { return "text"; }
Subroutine sql_type: not called CC=1 SCAR=6.9
522 0 ▶sub generate { return []; }
Subroutine generate: not called CC=1 SCAR=6.9
523 0 ▶sub data_type { return WWW::Shopify::Field::TYPE_QUALITATIVE; }
Subroutine data_type: not called CC=1 SCAR=6.9
524 0 ▶sub validate { return !defined $_[1] || (ref($_[1]) && ref($_[1]) eq "ARRAY"); }
Subroutine validate: not called CC=3 SCAR=24.8
Condition0%0/6
!defined($_[1]) || ref $_[1] && ref $_[1] eq 'ARRAY'
l!l&&r!l&&!r
000
ref $_[1] and ref $_[1] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
!defined($_[1]) || ref $_[1] && ref $_[1] eq 'ARRAY'
!defined($_[1]) ref $_[1] ref $_[1] eq "ARRAY"
Truth table0%0/4
not(A) || B and C
A= !defined($_[1])B= ref $_[1]C= ref $_[1] eq "ARRAY"
ABCresult
1XX1
0111
00X0
0100
525 0 ▶sub to_shopify { return $_[1]; }
Subroutine to_shopify: not called CC=1 SCAR=6.9
526 0 ▶sub from_shopify { return $_[1]; }
Subroutine from_shopify: not called CC=1 SCAR=6.9
527  
528 package WWW::Shopify::Field::Freeform::Hash;
529 1 ▶use base 'WWW::Shopify::Field::Freeform';
Subroutine BEGIN: called CC=1 SCAR=0.0
530 0 ▶sub sql_type { return "text"; }
Subroutine sql_type: not called CC=1 SCAR=6.9
531 0 ▶sub generate { return {}; }
Subroutine generate: not called CC=1 SCAR=6.9
532 0 ▶sub data_type { return WWW::Shopify::Field::TYPE_QUALITATIVE; }
Subroutine data_type: not called CC=1 SCAR=6.9
533 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
534 0 ▶sub to_shopify { return $_[1]; }
Subroutine to_shopify: not called CC=1 SCAR=6.9
535 0 ▶sub from_shopify { return $_[1]; }
Subroutine from_shopify: not called CC=1 SCAR=6.9
536  
537 1 1;
« Shopify/Exception.pm ↑ Summary Shopify/URLHandler/Queued.pm »