| 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 | =head1 NAME | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | WWW::Shopify::Test - A subclass of WWW::Shopify which represents a testing environment. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 DESCRIPTION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | A WWW::Shopify object that instead of making calls to a particular URL uses a database to represent an instance of a shopify store. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | In addition to providing a method to access the database, the test subclass also provides a method to generate entries in the database for testing purposes using the generate method. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 EXAMPLES | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | Should be used as L<WWW::Shopify> as a normal store. Prior to doing this, the object must be 'associated' with a particular store on our fake database. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | It can be done like the following: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | my $db = WWW::Shopify::Model::DBIx::Schema->connect('dbi:SQLite:dbname=' . tmpnam(), { RaiseError => 1, AutoCommit => 1 }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | $db->generate([WWW::Shopify::Model::Shop]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | my $sa = new WWW::Shopify::Test($db); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | $sa->associate_randomly(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | =head1 METHODS | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | A bunch of methods are unique to the WWW::Shopify::Test, and not part of the normal WWW::Shopify, namely the associate methods and the generate method; they are listed here. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | use WWW::Shopify; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | use WWW::Shopify::Common::DBIx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | use DateTime; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | package WWW::Shopify::Test; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | use parent 'WWW::Shopify'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | use String::Random qw(random_regex random_string); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | ▶ | use Data::Random; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | use List::Util qw(shuffle first); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | use Module::Find; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # Make sure we include all our models so that when people call the model, we actually know what they're talking about. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | BEGIN { eval(join("\n", map { "require $_;" } findallmod WWW::Shopify::Model)); die $@ if $@; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | my %api_recycle_times = (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | #sub CALL_LIMIT_REFRESH { return $ENV{'SHOPIFY_CALL_REFRESH'} ? $ENV{'SHOPIFY_CALL_REFRESH'} : WWW::Shopify->CALL_LIMIT_REFRESH; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub PULLING_ITEM_LIMIT { return $ENV{'SHOPIFY_PULLING_ITEM_LIMIT'} ? $ENV{'SHOPIFY_PULLING_ITEM_LIMIT'} : WWW::Shopify->PULLING_ITEM_LIMIT; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PULLING_ITEM_LIMIT: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub CALL_LIMIT_MAX { return $ENV{'SHOPIFY_CALL_MAX'} ? $ENV{'SHOPIFY_CALL_MAX'} : WWW::Shopify->CALL_LIMIT_MAX; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CALL_LIMIT_MAX: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub CALL_LIMIT_LEAK_TIME { return $ENV{'SHOPIFY_CALL_LEAK_TIME'} ? $ENV{'SHOPIFY_CALL_LEAK_TIME'} : WWW::Shopify->CALL_LIMIT_LEAK_TIME; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CALL_LIMIT_LEAK_TIME: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub CALL_LIMIT_LEAK_RATE { return $ENV{'SHOPIFY_CALL_LEAK_RATE'} ? $ENV{'SHOPIFY_CALL_LEAK_RATE'} : WWW::Shopify->CALL_LIMIT_LEAK_RATE; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CALL_LIMIT_LEAK_RATE: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | sub new { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | my ($package, $dbschema, $shop, $access_token) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | _db => $dbschema, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | _associatedShop => undef, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | _mapper => new WWW::Shopify::Common::DBIx(), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | _callback => undef, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | _access_token => $access_token | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | }, $package; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | ▶ | $self->associate($shop) if $shop; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | return $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub callback { $_[0]->{_callback} = $_[1] if defined $_[1]; return $_[0]->{_callback}; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
callback: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub access_token { $_[0]->{_access_token} = $_[1] if defined $_[1]; return $_[0]->{_access_token}; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
access_token: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | =head2 ASSOCIATION METHODS | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | =head3 associate | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | Takes in a Model::DBIx::Model::Shop. Associate this object with the shop, meaning that every call you make on this object will target that particular shop. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | This must be called (directly or indirectly) before any calls can be made to the shop. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | sub associate { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | my $self = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
associate: not called CC=6 SCAR=37.4
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if (defined $_[1]) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $shop = $_[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if (ref($shop)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | die ref($shop) unless ref($shop) =~ m/Model::.*Shop$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $self->{_associatedShop} = $shop; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | $api_recycle_times{$shop->id} = {calls => 0, recycled => time} if !exists $api_recycle_times{$shop->id}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $self->associate($self->{_db}->resultset('Model::Shop')->find({myshopify_domain => $shop})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | die new WWW::Shopify::Exception("Can't find shop $shop to associate with.") unless $self->associate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | return $self->{_associatedShop}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | =head3 associate_randomly | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | Calls associate with a random shop from the database. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | sub associate_randomly { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | my $self = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
associate_randomly: not called CC=2 SCAR=17.9
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my @shops = $self->{_db}->resultset('Model::Shop')->all(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | die new WWW::Shopify::Exception("Unable to associate randomly; no shops present.") unless int(@shops) > 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | return $self->associate($shops[rand(int(@shops))]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | =head3 associate_unlinked | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | Calls associate with a shop that is NOT in the list of urls that you pass into this function. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | $SA->associate_unlinked('hostname1', 'hostname2'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | sub associate_unlinked { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | my ($self, @ids) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
associate_unlinked: not called CC=2 SCAR=17.9
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my @shops = $self->{_db}->resultset('Model::Shop')->search( { myshopify_domain => { 'NOT IN' => [@ids] } } )->all(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | die new WWW::Shopify::Exception("Unable to associate unlinked; no unlinked shops.") unless int(@shops) > 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | return $self->associate($shops[rand(int(@shops))]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | =head3 associate_linked | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | Calls associate with a shop that is in the list of urls that you pass in to this function. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | $SA->associate_linked('hostname1', 'hostname2'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # Associates with a paricular shop that IS part of the app. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | sub associate_linked { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | my ($self, $ids) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
associate_linked: not called CC=2 SCAR=17.9
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $condition = map { { myshopify_domain => $_ } } @$ids; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my @shops = $self->{_db}->resultset('Model::Shop')->search( { myshopify_domain => { 'IN' => $ids } } )->all(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | die new WWW::Shopify::Exception("Unable to associate linked; no linked shops.") unless int(@shops) > 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | return $self->associate($shops[rand(int(@shops))]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | sub get_url($$@) { die new WWW::Shopify::Exception("Can't use URL methods on the test object."); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_url: not called CC=1 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub post_url($$@) { die new WWW::Shopify::Exception("Can't use URL methods on the test object."); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
post_url: not called CC=1 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | sub put_url($$@) { die new WWW::Shopify::Exception("Can't use URL methods on the test object."); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
put_url: not called CC=1 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | sub delete_url($$@) { die new WWW::Shopify::Exception("Can't use URL methods on the test object."); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete_url: not called CC=1 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | =head2 GENERATION METHODS | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | As of now, there's only one generation function. These functions generate objects for the underlying database. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | =head3 generate | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | The generate method. Generates a whole ton of stuff for your database. Doesn't have to be associate with a shop; generates shops as well. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | Essentially, what you want to do when you call this is pass in a list of class names (WWW::Shopify::Model:: style, not the DBIx ones) in an array, and this funciton will generate them, and if necessary their dependencies. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | It'll generate 50*(:: count - 2)^2 of the class (so WWW::Shopify::Model::Product'll get 50, but there'll be 200 WWW::Shopify::Model::Product::Variants) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | WWW::Shopify::Model::Shop is a special case, that's set to 6, basically for lulz. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | Calls go like so: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | $SA->generate(['WWW::Shopify::Model::Shop', 'WWW::Shopify::Model::Product']); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | Note, this can take a while, depending on the speed of your computer/virtual machine. Once it's finished, you should have a nice little database full of bogus data of the proper type. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | sub get_class { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | my ($self, $parent, $package, $ids) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_class: not called CC=1 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # Used to make objects make sense. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | sub correct_object { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | my ($self, $object) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
correct_object: not called CC=3 SCAR=24.8
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | if (ref($object) =~ m/Product$/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | my $i = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $_->update({ position => $i++ }) for ($object->options->all); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 1 | ▶ | use List::Util qw(shuffle); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 1 | ▶ | use JSON qw(encode_json); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | sub generate_class { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | ▶ | my ($self, $package, $ids, $parent, $restrictions) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_class: called CC=33 SCAR=62.7
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | ▶ | $ids = {} unless defined $ids; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | print STDERR "Generating $package...\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 1 | my $fields = $package->fields; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | my $object = $self->{_db}->resultset(transform_name($package))->new({}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # Simple fields. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | foreach my $field (grep { !$_->is_relation } values(%$fields)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 31 | my $name = $field->name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 31 | my $value = $field->generate(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # If it's a hash, encode it as JSON. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 31 | ▶ | $value = encode_json($value) if ref($value) && ref($value) eq "HASH"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $value and ref $value eq "HASH"
MC/DC0%0/2
ref $value and ref $value eq "HASH"
ref $value
ref $value eq "HASH"
Truth table33%1/3
A and B
A= ref $valueB= ref $value eq "HASH"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 31 | $object->$name($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 1 | ▶ | $ids->{$package} = [] unless defined $ids->{$package}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 1 | my $identifier = $package->identifier; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 1 | ▶ | if ($identifier eq "id" && $restrictions) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$identifier eq "id" and $restrictions
MC/DC0%0/2
$identifier eq "id" and $restrictions
$identifier eq "id"
$restrictions
Truth table33%1/3
A and B
A= $identifier eq "id"B= $restrictions
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my $tentative; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my %present = map { $_ => 1 } @{$ids->{$package}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | do { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | $tentative = int(rand($restrictions->[1] - $restrictions->[0])) + $restrictions->[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | } while (exists $present{$tentative}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | $object->$identifier($tentative); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 1 | my $id = $object->$identifier; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | push(@{$ids->{$package}}, $id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # Set parent ID. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 1 | my $parent_variable = $object->parent_variable; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 1 | ▶ | if ($parent_variable && ((!$package->parent && ref($parent) !~ m/Shop$/) || $package->parent)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition11%1/9
$parent_variable and !($package->parent || ref($parent) =~ /Shop$/) || $package->parent
not $package->parent || ref($parent) =~ /Shop$/ or $package->parent
$package->parent || ref($parent) =~ /Shop$/
MC/DC0%0/4
$parent_variable and !($package->parent || ref($parent) =~ /Shop$/) || $package->parent
$parent_variable
$package->parent
ref($parent) =~ /Shop$/
$package->parent
Truth table16%1/6
A and not(B || C) or D
A= $parent_variableB= $package->parentC= ref($parent) =~ /Shop$/D= $package->parent
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | my $parent_id = $parent->id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | die "Can't find parent for $package looking in " . $package->parent unless $ids->{$package->parent}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | my @ids = @{$ids->{$package->parent}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # If we have something that's basically not a shop. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | if ($parent->represents ne $package->parent) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | $parent_id = $ids[int(rand(int(@ids)))]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $object->$parent_variable($parent_id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # If we're not a shop and we don't have a parent, we have a shop_id field. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 1 | ▶ | if (WWW::Shopify::Common::DBIx::has_shop_field($object)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | die new WWW::Shopify::Exception("Everything not a shop requires a parent.") unless $parent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | $object->shop_id((ref($parent) !~ m/Shop$/) ? $parent->shop_id : $parent->id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # Simpler relationships. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 1 | $object = $object->insert; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | foreach my $field (grep { $_->is_relation && !$_->is_parent } values(%$fields)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | my $relation = $field->relation; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | if ($field->is_db_belongs_to && $field->db_rand_count > 0) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
$field->is_db_belongs_to and $field->db_rand_count > 0
MC/DC0%0/2
$field->is_db_belongs_to and $field->db_rand_count > 0
$field->is_db_belongs_to
$field->db_rand_count > 0
Truth table0%0/3
A and B
A= $field->is_db_belongs_toB= $field->db_rand_count > 0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | my $belongs_to; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | $self->generate_class($relation, $ids, $parent, $restrictions) unless ($ids->{$relation}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | $belongs_to = $ids->{$relation}->[rand(int(@{$ids->{$relation}}))]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | my $field_name = $field->name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | $field_name .= "_id" unless $field_name =~ m/_id$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $object->$field_name($belongs_to); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | ▶ | elsif ($field->is_db_has_one && $field->db_rand_count > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$field->is_db_has_one and $field->db_rand_count > 0
MC/DC0%0/2
$field->is_db_has_one and $field->db_rand_count > 0
$field->is_db_has_one
$field->db_rand_count > 0
Truth table0%0/3
A and B
A= $field->is_db_has_oneB= $field->db_rand_count > 0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $self->generate_class($relation, $ids, $object, $restrictions); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | elsif ($field->is_db_has_many) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | my $many_count = $field->db_rand_count; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | for (my $c = 0; $c < $many_count; ++$c) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | $self->generate_class($relation, $ids, $object, $restrictions); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | $self->correct_object($object); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | $object->update; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # Many-Many | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | foreach my $field (grep { $_->is_relation && $_->is_db_many_many } values(%$fields)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | my $relation = $field->relation; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | #next if $relation =~ m/Metafield/i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my $accessor = "add_to_" . $field->name . "_hasmany"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | if (defined $ids->{$relation}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my $many_count = $field->db_rand_count; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | for (my $c = 0; $c < $many_count; ++$c) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | $self->generate_class($relation, $ids, $parent, $restrictions); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | my @shuffled = shuffle(@{$ids->{$relation}}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | $object->$accessor({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | $package->singular . "_id" => $id, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | $relation->singular . "_id" => $_ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | }) for (grep { defined $_ } @shuffled[0..rand(5)]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | return $object; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | sub finalize_class { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | my ($self, $object) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finalize_class: not called CC=2 SCAR=17.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | my $package = ref($object); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | my %dispatch_table = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my $sub = $dispatch_table{$package}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | $object = $sub->($object) if $sub; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | return $object; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 1 | ▶ | use List::Util qw(max); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | sub check_increment_calls { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_increment_calls: not called CC=4 SCAR=30.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | $self->last_timestamp(DateTime->now); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | die new WWW::Shopify::Exception::InvalidKey() unless $self->access_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | my $duration = time - $api_recycle_times{$self->associate->id}->{recycled}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | my $api_calls = $api_recycle_times{$self->associate->id}->{calls}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | print STDERR "ID: " . $self->associate->id . " Seconds: " . $duration . " Calls: " . $api_recycle_times{$self->associate->id}->{calls} . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $api_calls = max(0, $api_calls - (int($duration / $self->CALL_LIMIT_LEAK_TIME) * $self->CALL_LIMIT_LEAK_RATE)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | $self->reset_call_limit($api_calls); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | if ($api_calls == $self->CALL_LIMIT_MAX) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | if ($self->sleep_for_limit) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | sleep(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | $duration = time - $api_recycle_times{$self->associate->id}->{recycled}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | $api_calls = $api_recycle_times{$self->associate->id}->{calls}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | $api_calls = max(0, $api_calls - (int($duration / $self->CALL_LIMIT_LEAK_TIME) * $self->CALL_LIMIT_LEAK_RATE)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | $self->reset_call_limit($api_calls); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | die WWW::Shopify::Exception::CallLimit->new(HTTP::Response->new(429, "API Call Limit Reached")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $self->api_calls($api_calls + 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | $api_recycle_times{$self->associate->id}->{calls} = $api_calls+1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | sub reset_call_limit { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | my ($self, $calls) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset_call_limit: not called CC=2 SCAR=17.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | die new WWW::Shopify::Exception("Cannot reset call limit on unassociated api.") unless $self->associate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | $api_recycle_times{$self->associate->id}->{calls} = $calls; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $api_recycle_times{$self->associate->id}->{recycled} = time; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | sub reset_all_calls { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | for (keys(%api_recycle_times)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset_all_calls: not called CC=2 SCAR=17.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | $api_recycle_times{$_}->{calls} = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | $api_recycle_times{$_}->{recycled} = time; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | sub check_scope { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | my ($self, $package, $read_write) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_scope: not called CC=1 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | sub get_timestamp { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | return DateTime->now->subtract( seconds => 6); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_timestamp: not called CC=1 SCAR=6.9
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | #use Sys::CPU; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | #use threads; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 1 | my $internal_range = 1000000000; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 1 | ▶ | use List::Util qw(min); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 1 | ▶ | use List::MoreUtils qw(part); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | sub generate { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 1 | ▶ | my ($self, %items) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate: called CC=2 SCAR=11.9
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | # 0 is auto-pick. Each is on a per-item basis. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | # Take at least 5 shops. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 1 | my $shop_count = $items{'WWW::Shopify::Model::Shop'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 1 | ▶ | $shop_count = 5 unless defined $shop_count; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | #my $cpu_count = min(Sys::CPU::cpu_count(), $shop_count); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | #$cpu_count = min($ENV{'CPU'}, $cpu_count) if $ENV{'CPU'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | #$cpu_count = 1 unless $ENV{'CPU'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 1 | my $cpu_count = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 1 | print STDERR "Beginning generation of $shop_count shops on $cpu_count threads...\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 1 | my $i = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 1 | ▶ | my @partitions = part { $i++ % $cpu_count } 1..$shop_count; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | sub generate_thread { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 1 | ▶ | my ($self, $partitions, $items) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_thread: called CC=15 SCAR=49.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 1 | foreach my $initial_range (@$partitions) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 1 | my $min_range = $initial_range * $internal_range; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 1 | my $max_range = ($initial_range+1) * $internal_range; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 1 | print STDERR "====== GENERATING SHOP =======\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 1 | my %ids = ( ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 1 | my $shop = $self->generate_class('WWW::Shopify::Model::Shop', \%ids); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | %ids = ( 'WWW::Shopify::Model::Shop' => [$shop->id] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | my %counts = map { $_ => $items->{$_} } grep { $_ !~ m/Shop$/ } keys(%$items); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | while (int(keys(%counts)) > 0) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | # This should be really fixed. We really shouldn't have to do this. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | my @keys = sort { ((($a =~ m/Checkout/) ? 11 : 0) + ($a =~ m/Order/ ? 10 : 0) + ($a =~ m/Customer/ ? 9 : 0) + ($a =~ m/Transaction/ ? 12 : 0) + $a->nested_level + ($self->{_mapper}->transform_package($a)->parent_variable ? 1 : 0)) <=> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | ((($b =~ m/Checkout/) ? 11 : 0) + ($b =~ m/Order/ ? 10 : 0) + ($b =~ m/Customer/ ? 9 : 0) + ($b =~ m/Transaction/ ? 12 : 0) + $b->nested_level + ($self->{_mapper}->transform_package($b)->parent_variable ? 1 : 0)) } keys(%counts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 10 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | foreach my $item (@keys) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | $self->{_db}->txn_do(sub { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | $self->generate_class($item, \%ids, $shop, [$min_range, $max_range]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | delete $counts{$item} if (--$counts{$item} == 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | print STDERR "====== SHOP FINISHED =======\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | #if ($cpu_count > 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | #my @threads = map { threads->create('generate_thread', $self, $partitions[$_], \%items) } (1..$cpu_count); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | #$_->join() for (@threads); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | #} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | #else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 1 | generate_thread($self, $partitions[0], \%items); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | #} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | sub transform_name($) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 1 | ▶ | die "Improperly formatted package: " . $_[0] unless $_[0] =~ /WWW::Shopify::(.+)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
transform_name: called CC=2 SCAR=7.2
Pod
undocumented
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 1 | return $1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 1 | ▶ | use WWW::Shopify::Query; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 1 | ▶ | use List::Util qw(first); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | sub generate_conditions { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | my ($self, $package, $specs, $rs) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_conditions: not called CC=19 SCAR=59.4
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | my %conditions = (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | my $queries = $package->queries; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | $rs = $rs->search({}, { rows => $self->PULLING_ITEM_LIMIT, page => $specs->{page} }) if exists $specs->{limit} && exists $specs->{page}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $specs->{"limit"} and exists $specs->{"page"}
MC/DC0%0/2
exists $specs->{"limit"} and exists $specs->{"page"}
exists $specs->{"limit"}
exists $specs->{"page"}
Truth table0%0/3
A and B
A= exists $specs->{"limit"}B= exists $specs->{"page"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | $rs = $rs->search({}, { rows => $specs->{limit} }) if exists $specs->{limit} && !exists $specs->{page}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $specs->{"limit"} and not exists $specs->{"page"}
MC/DC0%0/2
exists $specs->{"limit"} and not exists $specs->{"page"}
exists $specs->{"limit"}
not exists $specs->{"page"}
Truth table0%0/3
A and not(B)
A= exists $specs->{"limit"}B= not exists $specs->{"page"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | my %override = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 'WWW::Shopify::Model::Order' => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 'status' => sub { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | my ($rs, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | return $rs if $value eq "any"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | return $rs->search({ closed_at => undef, cancelled_at => undef }) if $value eq "open"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | return $rs->search({ cancelled_at => { '!=' => undef } }) if $value eq "cancelled"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | return $rs->search({ closed_at => { '!=' => undef } }) if $value eq "closed"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | foreach my $query (values(%$queries)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | next unless exists $specs->{$query->name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | my $value = $specs->{$query->name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | $value = $self->{_db}->storage->datetime_parser->format_datetime($value) if ref($value) eq "DateTime"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | if ($override{$package} && $override{$package}->{$query->name}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$override{$package} and $override{$package}{$query->name}
MC/DC0%0/2
$override{$package} and $override{$package}{$query->name}
$override{$package}
$override{$package}{$query->name}
Truth table0%0/3
A and B
A= $override{$package}B= $override{$package}{$query->name}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | my $sub = $override{$package}->{$query->name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | $rs = &$sub($rs, $value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | $conditions{$query->field_name} = {} unless exists $conditions{$query->field_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | if (ref($query) =~ m/LowerBound$/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | $conditions{$query->field_name}->{'>='} = $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | elsif (ref($query) =~ m/UpperBound$/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | $conditions{$query->field_name}->{'<='} = $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | elsif (ref($query) =~ m/Enum$/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | $conditions{$query->field_name} = $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | die new WWW::Shopify::Exception("Can't specify $value for enum " . $query->name . ", must be one of the following: " . join(", ", $query->enums)) unless | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | first { $_ eq $value } $query->enums; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | delete $conditions{$query->field_name} if $value eq "any"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | elsif (ref($query) =~ m/Match$/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | $conditions{$query->field_name} = $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | elsif (ref($query) =~ m/Custom$/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | $rs = $query->routine->($rs, $value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | # We keep the conditions hash because of legacy reasons. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | $rs = $rs->search({%conditions}) if %conditions; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | return $rs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | sub filter_gettable { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | ▶ | my ($self, $obj) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
filter_gettable: not called CC=11 SCAR=48.8
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | my %fields = map { $_ => 1 } $obj->get_fields; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | my @keys = keys(%{$obj->fields}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | foreach my $key (@keys) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | if (!$fields{$key}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | delete $obj->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | elsif ($obj->{$key}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | ▶ | if (ref($obj->{$key}) =~ m/WWW::Shopify::Model/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | $self->filter_gettable($obj->{$key}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | elsif (ref($obj->{$key}) eq "ARRAY") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | for (grep { $_ && ref($_) =~ m/WWW::Shopify::Model/ } @{$obj->{$key}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | $self->filter_gettable($_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | elsif (ref($obj->{$key}) eq "HASH") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | ▶ | for (grep { $_ && ref($_) =~ m/WWW::Shopify::Model/ } values(%{$obj->{$key}})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | $self->filter_gettable($_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | return $obj; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 1 | ▶ | use POSIX qw(ceil); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 1 | ▶ | use Data::Dumper; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | sub get_all_limit { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | my ($self, $package, $specs) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_all_limit: not called CC=10 SCAR=47.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | ▶ | die new WWW::Shopify::Exception("WWW::Shopify::Test object not associated with shop. Call associate.") unless $self->associate(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | ▶ | $specs->{"limit"} = $self->PULLING_ITEM_LIMIT unless $specs->{"limit"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | return () if ($specs->{limit} == 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | $package = $self->translate_model($package); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | $self->validate_item($package); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | ▶ | return $self->get_shop if $package->is_shop; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | $self->resolve_trailing_url($package, "get", $specs->{parent}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | my @return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | my $rs = undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | ▶ | if ($package =~ m/Metafield/ && $specs->{parent}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$package =~ /Metafield/ and $specs->{"parent"}
MC/DC0%0/2
$package =~ /Metafield/ and $specs->{"parent"}
$package =~ /Metafield/
$specs->{"parent"}
Truth table0%0/3
A and B
A= $package =~ /Metafield/B= $specs->{"parent"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | my $parent = $self->{_mapper}->from_shopify($self->{_db}, $specs->{parent}, $self->associate->id)->contents; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | $rs = $parent->metafields->search({ 'metafield.shop_id' => $self->associate->id() }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | $rs = $self->{_db}->resultset(transform_name($package))->search({ 'me.shop_id' => $self->associate()->id() }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | ▶ | if ($package->get_through_parent) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | $rs = $rs->search({ 'me.' . $self->{_mapper}->transform_package($package)->parent_variable => $specs->{parent}->id }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | $rs = $self->generate_conditions($package, $specs, $rs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | $rs = $rs->search({ }, { rows => $specs->{limit} }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | print STDERR Dumper([$rs->as_query]) if $ENV{'SHOPIFY_LOG'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | @return = $rs->all; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | my $call_count = ceil($specs->{limit} / $self->PULLING_ITEM_LIMIT); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | $self->check_increment_calls for (1..$call_count); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | return map { my $obj = $self->{_mapper}->to_shopify($_, $self); $obj->associated_parent($specs->{parent}); $self->filter_gettable($obj) } @return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | sub search { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | ▶ | my ($self, $package, $specs) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
search: not called CC=10 SCAR=47.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | ▶ | die new WWW::Shopify::Exception("WWW::Shopify::Test object not associated with shop. Call associate.") unless $self->associate(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | $package = $self->translate_model($package); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | ▶ | die new WWW::Shopify::Exception("Unable to search $package; it is not marked as searchable in Shopify's API.") unless $package->searchable; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | die new WWW::Shopify::Exception("Must have a query to search.") unless $specs && $specs->{query}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$specs and $specs->{"query"}
MC/DC0%0/2
$specs and $specs->{"query"}
$specs
$specs->{"query"}
Truth table0%0/3
A and B
A= $specsB= $specs->{"query"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | $self->validate_item($package); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | $self->resolve_trailing_url($package, "get", $specs->{parent}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | my @criteria = split(/\s+/, $specs->{query}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | my %values = map { my @inner = split(/:/, $_); $inner[0] => $inner[1] } @criteria; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | my $rs = $self->{_db}->resultset(transform_name($package))->search({ 'me.shop_id' => $self->associate()->id(), map { $_ => { like => '%' . $values{$_} . '%' } } keys(%values) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | ▶ | print STDERR Dumper([$rs->as_query]) if $ENV{'SHOPIFY_LOG'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | my @return = $rs->all; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | ▶ | $specs->{"limit"} = $self->PULLING_ITEM_LIMIT unless $specs->{"limit"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | my $call_count = ceil($specs->{limit} / $self->PULLING_ITEM_LIMIT); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | $self->check_increment_calls for (1..$call_count); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | @return = map { my $obj = $self->{_mapper}->to_shopify($_, $self); $obj->associate($self); $self->filter_gettable($obj) } @return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | ▶ | return @return if wantarray; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | ▶ | return $return[0] if int(@return) > 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | sub get_shop { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | ▶ | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_shop: not called CC=2 SCAR=17.9
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | ▶ | die new WWW::Shopify::Exception("WWW::Shopify::Test object not associated with shop. Call associate.") unless $self->associate(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | $self->check_increment_calls; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | my $obj = $self->{_mapper}->to_shopify($self->associate(), $self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | return $self->filter_gettable($obj); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | sub get_count { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | ▶ | my ($self, $package, $specs) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_count: not called CC=9 SCAR=45.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | ▶ | die new WWW::Shopify::Exception("WWW::Shopify::Test object not associated with shop. Call associate.") unless $self->associate(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | $self->check_increment_calls; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | $package = $self->translate_model($package); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | ▶ | die new WWW::Shopify::Exception("Can't count $package.") unless $package->countable; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | die new WWW::Shopify::Exception("Can't count $package unless has parent.") if $package->count_through_parent && !$specs->{parent}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$package->count_through_parent and not $specs->{"parent"}
MC/DC0%0/2
$package->count_through_parent and not $specs->{"parent"}
$package->count_through_parent
not $specs->{"parent"}
Truth table0%0/3
A and not(B)
A= $package->count_through_parentB= not $specs->{"parent"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | $self->validate_item($package); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | $self->resolve_trailing_url($package, "get", $specs->{parent}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | my $rs = $self->{_db}->resultset(transform_name($package))->search({ 'me.shop_id' => $self->associate()->id() }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | $rs = $self->generate_conditions($package, $specs, $rs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | ▶ | if ($package =~ m/Metafield/ && $specs->{parent}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$package =~ /Metafield/ and $specs->{"parent"}
MC/DC0%0/2
$package =~ /Metafield/ and $specs->{"parent"}
$package =~ /Metafield/
$specs->{"parent"}
Truth table0%0/3
A and B
A= $package =~ /Metafield/B= $specs->{"parent"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | my $parent = $self->{_mapper}->from_shopify($self->{_db}, $specs->{parent}, $self->associate->id)->contents; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | $rs = $parent->metafields->search({ 'metafield.shop_id' => $self->associate->id() }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | $rs = $self->{_db}->resultset(transform_name($package))->search({ 'me.shop_id' => $self->associate()->id() }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | ▶ | if ($package->get_through_parent) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | $rs = $rs->search({ 'me.' . $self->{_mapper}->transform_package($package)->parent_variable => $specs->{parent}->id }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | $rs = $self->generate_conditions($package, $specs, $rs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | ▶ | print STDERR Dumper([$rs->as_query]) if $ENV{'SHOPIFY_LOG'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | return $rs->count; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | sub get { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | ▶ | my ($self, $package, $id, $specs) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: not called CC=5 SCAR=34.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | ▶ | die new WWW::Shopify::Exception("WWW::Shopify::Test object not associated with shop. Call associate.") unless $self->associate(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | $self->check_increment_calls; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | $package = $self->translate_model($package); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | $self->validate_item($package); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | $self->resolve_trailing_url($package, "get", $specs->{parent}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | my $rs = $self->{_db}->resultset(transform_name($package))->search({ 'me.shop_id' => $self->associate()->id(), ('me.' . $package->identifier) => $id }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | ▶ | print STDERR Dumper([$rs->as_query]) if $ENV{'SHOPIFY_LOG'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | my $row = $rs->first; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | ▶ | return undef unless $row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | my $obj = $self->{_mapper}->to_shopify($row, $self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | ▶ | $obj->associate($self) if $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | return $self->filter_gettable($obj); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | # Fields that should be filled in by 'shopify'. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | sub post_creation_fields { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | ▶ | my ($self, $item) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
post_creation_fields: not called CC=5 SCAR=34.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | ▶ | if (ref($item) =~ m/ApplicationCharge/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | $item->status("pending"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | $item->confirmation_url("/mock/charge_activation/" . $item->id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | elsif (ref($item) =~ m/Discount/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | $item->status("enabled"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | ▶ | $item->created_at(DateTime->now) if ($item->has_column('created_at')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | ▶ | $item->updated_at(DateTime->now) if ($item->has_column('updated_at')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | sub create { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | ▶ | my ($self, $item, $options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: not called CC=11 SCAR=48.8
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | die new WWW::Shopify::Exception("WWW::Shopify::Test object not associated with shop. Call associate.") unless $self->associate(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | $self->check_increment_calls; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | # Helps to have a little delay from time to time. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | sleep(int(rand()*3)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | $self->validate_item(ref($item)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | my $package = ref($item); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | my @missing = grep { !exists $item->{$_} } $item->creation_minimal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | ▶ | die "Missing minimal creation member(s) " . join(", ", @missing) . "." if @missing; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | ▶ | die new WWW::Shopify::Exception(ref($item) . " requires you to login with an admin account.") if $item->needs_login && !$self->logged_in_admin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$item->needs_login and not $self->logged_in_admin
MC/DC0%0/2
$item->needs_login and not $self->logged_in_admin
$item->needs_login
not $self->logged_in_admin
Truth table0%0/3
A and not(B)
A= $item->needs_loginB= not $self->logged_in_admin
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | $self->resolve_trailing_url($item, "create", $item->associated_parent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | my $dbixgroup = $self->{_mapper}->from_shopify($self->{_db}, $item); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | sub fill_creation { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | ▶ | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fill_creation: not called CC=10 SCAR=47.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | my %chosen_ids = (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | foreach my $item (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | my $fields = $item->represents->fields; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | my @fillable_on_creation = $item->represents->creation_filled; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | for (@fillable_on_creation) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | # This will automatically be filled by add_to_ accessors. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | ▶ | die new WWW::Shopify::Exception("Unable to generate field $_ in $item; doens't exist in fields.") unless exists $fields->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | ▶ | next if $fields->{$_}->is_relation() && $fields->{$_}->is_parent(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$fields->{$_}->is_relation and $fields->{$_}->is_parent
MC/DC0%0/2
$fields->{$_}->is_relation and $fields->{$_}->is_parent
$fields->{$_}->is_relation
$fields->{$_}->is_parent
Truth table0%0/3
A and B
A= $fields->{$_}->is_relationB= $fields->{$_}->is_parent
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | ▶ | die new WWW::Shopify::Exception("Unable to generate field $_ in $item; can't generate relations.") if $fields->{$_}->is_relation(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | $item->$_($fields->{$_}->generate()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | ▶ | if (exists $fields->{id}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | while (1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | my $id = int(rand(10000000)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | $item->id($id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | my $test = $self->{_db}->resultset(transform_name($item->represents))->find($id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | ▶ | last unless defined $test && !exists $chosen_ids{$id}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $test and not exists $chosen_ids{$id}
MC/DC0%0/2
defined $test and not exists $chosen_ids{$id}
defined $test
not exists $chosen_ids{$id}
Truth table0%0/3
A and not(B)
A= defined $testB= not exists $chosen_ids{$id}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | $chosen_ids{$item->id} = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | $item->shop_id($self->associate->id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 0 | $self->post_creation_fields($item); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | fill_creation($self, $dbixgroup->nested); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | my %validities = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | ▶ | 'WWW::Shopify::Model::Order::Fulfillment' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | # my ($item) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | # my $order = $item->parent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | # my @fulfillments = $order->fulfillments->all; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | # if ($order-> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | #my $represents = $dbixgroup->contents->represents; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | #my $sub = $validities{$represents}($dbixgroup->contents) if $validites{$represents}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | my $return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | ▶ | if ($item->associated_parent && ref($item) =~ m/Metafield/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$item->associated_parent and ref($item) =~ /Metafield/
MC/DC0%0/2
$item->associated_parent and ref($item) =~ /Metafield/
$item->associated_parent
ref($item) =~ /Metafield/
Truth table0%0/3
A and B
A= $item->associated_parentB= ref($item) =~ /Metafield/
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | my $dbname = ref($item->associated_parent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | $dbname =~ s/WWW::Shopify:://; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | my $accessor = "add_to_" . $item->plural; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | my $parent = $self->{_db}->resultset($dbname)->find($item->associated_parent->id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | ▶ | die "Requires parent in database." unless $parent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | my $json = $item->to_json; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | $json->{shop_id} = $self->associate->id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | $parent->$accessor($json); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | $dbixgroup->insert; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | $return = $self->{_mapper}->to_shopify($dbixgroup->contents, $self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 0 | $return->associate($self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | ▶ | if ($@) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | die new WWW::Shopify::Exception(new HTTP::Response(422, "$@")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | ▶ | $self->callback->webhook($self->associate, $item, "create") if $self->callback && $item->throws_create_webhooks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->callback and $item->throws_create_webhooks
MC/DC0%0/2
$self->callback and $item->throws_create_webhooks
$self->callback
$item->throws_create_webhooks
Truth table0%0/3
A and B
A= $self->callbackB= $item->throws_create_webhooks
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | return $return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | sub update { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 0 | ▶ | my ($self, $item) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: not called CC=7 SCAR=40.3
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | ▶ | die new WWW::Shopify::Exception("WWW::Shopify::Test object not associated with shop. Call associate.") unless $self->associate(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | ▶ | die new WWW::Shopify::Exception(ref($item) . " requires you to login with an admin account.") if $item->needs_login && !$self->logged_in_admin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$item->needs_login and not $self->logged_in_admin
MC/DC0%0/2
$item->needs_login and not $self->logged_in_admin
$item->needs_login
not $self->logged_in_admin
Truth table0%0/3
A and not(B)
A= $item->needs_loginB= not $self->logged_in_admin
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | $self->validate_item(ref($item)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | $self->check_increment_calls; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 0 | $self->resolve_trailing_url($item, "update", $item->associated_parent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 0 | my $dbixgroup = $self->{_mapper}->from_shopify($self->{_db}, $item); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | ▶ | $dbixgroup->contents->updated_at(DateTime->now) if $item->fields->{updated_at}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | $dbixgroup->update; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | my $obj = $self->{_mapper}->to_shopify($dbixgroup->contents, $self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | $obj->associate($self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | ▶ | $self->callback->webhook($self->associate, $item, "update") if $self->callback && $item->throws_update_webhooks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->callback and $item->throws_update_webhooks
MC/DC0%0/2
$self->callback and $item->throws_update_webhooks
$self->callback
$item->throws_update_webhooks
Truth table0%0/3
A and B
A= $self->callbackB= $item->throws_update_webhooks
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | return $obj; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | sub delete { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | ▶ | my ($self, $item) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=9 SCAR=45.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | ▶ | die new WWW::Shopify::Exception("WWW::Shopify::Test object not associated with shop. Call associate.") unless $self->associate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 0 | ▶ | die new WWW::Shopify::Exception(ref($item) . " requires you to login with an admin account.") if $item->needs_login && !$self->logged_in_admin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$item->needs_login and not $self->logged_in_admin
MC/DC0%0/2
$item->needs_login and not $self->logged_in_admin
$item->needs_login
not $self->logged_in_admin
Truth table0%0/3
A and not(B)
A= $item->needs_loginB= not $self->logged_in_admin
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | $self->validate_item(ref($item)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | ▶ | die new WWW::Shopify::Exception("Class in deletion must be not null, and must be a blessed reference to a model object: " . ref($item)) unless ref($item) =~ m/Model/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | $self->check_increment_calls; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | $self->resolve_trailing_url($item, "delete", $item->associated_parent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | my $dbixgroup = $self->{_mapper}->from_shopify($self->{_db}, $item); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | ▶ | die new WWW::Shopify::Exception($item->singular . " with id " . $item->id . " does not exist.") unless $dbixgroup->contents->in_storage; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | ▶ | if (ref($item) =~ m/ApplicationCharge/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 0 | $dbixgroup->contents->status('cancelled'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | $dbixgroup->contents->update; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | $dbixgroup->delete; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | ▶ | $self->callback->webhook($self->associate, $item, "delete") if $self->callback && $item->throws_delete_webhooks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->callback and $item->throws_delete_webhooks
MC/DC0%0/2
$self->callback and $item->throws_delete_webhooks
$self->callback
$item->throws_delete_webhooks
Truth table0%0/3
A and B
A= $self->callbackB= $item->throws_delete_webhooks
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 0 | return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | # For orders, among others. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | sub close { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | ▶ | my ($self, $class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
close: not called CC=5 SCAR=34.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 0 | ▶ | die new WWW::Shopify::Exception("Only orders can be closed.") unless defined $class && $class->can_close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $class and $class->can_close
MC/DC0%0/2
defined $class and $class->can_close
defined $class
$class->can_close
Truth table0%0/3
A and B
A= defined $classB= $class->can_close
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 0 | $self->check_increment_calls; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | $self->validate_item(ref($class)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 0 | $self->resolve_trailing_url($class, "close", $class->associated_parent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | my $object = $self->{_db}->resultset(transform_name(ref($class)))->find({ id => $class->id() }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | ▶ | die new WWW::Shopify::Exception("Unable to find orders with id: " . $class->id()) unless defined $object; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 0 | ▶ | die new WWW::Shopify::Exception("Unable to close " . $class->singular . " " . $class->id . "; is already closed!") | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | if $object->closed_at; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 0 | $object->closed_at(DateTime->now); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | $object->update; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | my $obj = $self->{_mapper}->to_shopify($object, $self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | $obj->associate($self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | return $obj; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | # This function is solely for charges. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | sub activate { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | ▶ | my ($self, $class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
activate: not called CC=4 SCAR=30.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 0 | ▶ | die new WWW::Shopify::Exception("Only charges can be activated.") unless defined $class && $class->can_activate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $class and $class->can_activate
MC/DC0%0/2
defined $class and $class->can_activate
defined $class
$class->can_activate
Truth table0%0/3
A and B
A= defined $classB= $class->can_activate
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 0 | $self->check_increment_calls; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | $self->validate_item(ref($class)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | $self->resolve_trailing_url($class, "activate", $class->associated_parent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 0 | my $object = $self->{_db}->resultset(transform_name(ref($class)))->find({ id => $class->id() }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | ▶ | die new WWW::Shopify::Exception("Unable to find charge with id: " . $object->id()) unless defined $object; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | $object->status("active"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | $object->update; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | my $obj = $self->{_mapper}->to_shopify($object, $self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | $obj->associate($self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 0 | return $obj; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | sub disable { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | ▶ | my ($self, $class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disable: not called CC=6 SCAR=37.4
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 0 | ▶ | die new WWW::Shopify::Exception("You can only disable discount codes.") unless defined $class && $class->can_disable; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $class and $class->can_disable
MC/DC0%0/2
defined $class and $class->can_disable
defined $class
$class->can_disable
Truth table0%0/3
A and B
A= defined $classB= $class->can_disable
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 0 | ▶ | die new WWW::Shopify::Exception(ref($class) . " requires you to login with an admin account.") if $class->needs_login && !$self->logged_in_admin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$class->needs_login and not $self->logged_in_admin
MC/DC0%0/2
$class->needs_login and not $self->logged_in_admin
$class->needs_login
not $self->logged_in_admin
Truth table0%0/3
A and not(B)
A= $class->needs_loginB= not $self->logged_in_admin
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 0 | $self->check_increment_calls; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 0 | $self->validate_item(ref($class)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | $self->resolve_trailing_url($class, "disable", $class->associated_parent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 0 | my $object = $self->{_db}->resultset(transform_name(ref($class)))->find({ id => $class->id }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 0 | ▶ | die new WWW::Shopify::Exception("Unable to find discount code with id: " . $object->id) unless defined $object; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 0 | $object->status("disabled"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | $object->update; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | my $obj = $self->{_mapper}->to_shopify($object, $self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 0 | $obj->associate($self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 0 | return $obj; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | sub enable { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 0 | ▶ | my ($self, $class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enable: not called CC=6 SCAR=37.4
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 0 | ▶ | die new WWW::Shopify::Exception("You can only enable discount codes.") unless defined $class && $class->can_enable; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $class and $class->can_enable
MC/DC0%0/2
defined $class and $class->can_enable
defined $class
$class->can_enable
Truth table0%0/3
A and B
A= defined $classB= $class->can_enable
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | ▶ | die new WWW::Shopify::Exception(ref($class) . " requires you to login with an admin account.") if $class->needs_login && !$self->logged_in_admin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$class->needs_login and not $self->logged_in_admin
MC/DC0%0/2
$class->needs_login and not $self->logged_in_admin
$class->needs_login
not $self->logged_in_admin
Truth table0%0/3
A and not(B)
A= $class->needs_loginB= not $self->logged_in_admin
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | $self->check_increment_calls; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 0 | $self->validate_item(ref($class)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 0 | $self->resolve_trailing_url($class, "enable", $class->associated_parent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | my $object = $self->{_db}->resultset(transform_name(ref($class)))->find({ id => $class->id }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | ▶ | die new WWW::Shopify::Exception("Unable to find discount code with id: " . $object->id) unless defined $object; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 0 | $object->status("enabled"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 0 | $object->update; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 0 | my $obj = $self->{_mapper}->to_shopify($object, $self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 0 | $obj->associate($self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 0 | return $obj; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 1 | ▶ | use Digest::MD5 qw(md5_hex); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | sub login_admin { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 0 | ▶ | my ($self, $username, $password) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
login_admin: not called CC=3 SCAR=24.8
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 0 | ▶ | return 1 if $self->{last_login_check} && (time - $self->{last_login_check}) < 1000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"last_login_check"} and time - $self->{"last_login_check"} < 1000
MC/DC0%0/2
$self->{"last_login_check"} and time - $self->{"last_login_check"} < 1000
$self->{"last_login_check"}
time - $self->{"last_login_check"} < 1000
Truth table0%0/3
A and B
A= $self->{"last_login_check"}B= time - $self->{"last_login_check"} < 1000
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 0 | $self->{last_login_check} = time; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 0 | $self->{authenticity_token} = md5_hex(rand()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 0 | return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | sub logged_in_admin { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 0 | ▶ | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logged_in_admin: not called CC=3 SCAR=24.8
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 0 | ▶ | return 1 if $self->{last_login_check} && (time - $self->{last_login_check}) < 1000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"last_login_check"} and time - $self->{"last_login_check"} < 1000
MC/DC0%0/2
$self->{"last_login_check"} and time - $self->{"last_login_check"} < 1000
$self->{"last_login_check"}
time - $self->{"last_login_check"} < 1000
Truth table0%0/3
A and B
A= $self->{"last_login_check"}B= time - $self->{"last_login_check"} < 1000
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | 0 | $self->{last_login_check} = time; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 0 | return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | =head2 authorize_url([scope], redirect) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | When the shop doesn't have an access_token, this is what you should be redirecting your client to. Inputs should be your scope, as an array, and the url you want to redirect to. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 1 | ▶ | use URI::Escape; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | sub authorize_url { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | ▶ | my ($self, $scope, $redirect) = (@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
authorize_url: not called CC=1 SCAR=6.9
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 0 | return "/mock/admin/oauth/authorize?redirect_uri=" . uri_escape($redirect) . "&shop=" . $self->associate->myshopify_domain . "&scope=" . uri_escape(join(",", @$scope)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | =head2 exchange_token(shared_secret, code) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | When you have a temporary code, which you should get from authorize_url's redirect and you want to exchange it for a token, you call this. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | sub exchange_token { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 0 | ▶ | my ($self, $shared_secret, $code) = (@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exchange_token: not called CC=2 SCAR=17.9
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 0 | ▶ | die new WWW::Shopify::Exception("Unable to exchange tokens when shop is not associated.") unless $self->associate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 0 | my $req = HTTP::Request->new(POST => "https://" . $self->shop_url . "/admin/oauth/access_token"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 0 | $req->content_type('application/x-www-form-urlencoded'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 0 | my %parameters = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 'client_id' => $self->api_key, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 'client_secret' => $shared_secret, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 'code' => $code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 0 | sleep 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 0 | return md5_hex($self->api_key . $self->shop_url); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | sub shop_url { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 0 | ▶ | die new WWW::Shopify::Exception("Can't get a url, unless we're associated.") unless $_[0]->associate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shop_url: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 0 | return $_[0]->associate->myshopify_domain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 0 | ▶ | sub api_key { return md5_hex(''); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
api_key: not called CC=1 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | =head1 SEE ALSO | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | L<WWW::Shopify> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | =head1 AUTHOR | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | Adam Harrison | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | =head1 LICENSE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | See LICENSE in the main directory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 1 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||