blib/lib/WWW/Shopify/Login.pm

filter: Statementstmt 14.4% 13 / 90 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 20.0% 4 / 20 Podpod 12.5% 2 / 16 totaltotal 10.9% 19 / 173 CC 24 SCAR 34.1
CC
24
Cov
10%
update_x_shopify_api_features
110.0
get_all
12.0
create_update_locale_translation
12.0
CRAP 30.3
« blib/lib/WWW/Shopify.pm ↑ Summary blib/lib/WWW/Shopify/Model/LinkList/Link.pm »
1 #!/usr/bin/perl
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # All the extra functionality relating to the admin panel should go in here.
8 package WWW::Shopify::Login;
9 1 ▶use parent 'WWW::Shopify';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub get_all {
12 0 ▶ my ($self, $package, $hash) = @_;
Subroutine get_all: not called CC=3 SCAR=24.8
Pod documented
13 0 ▶ if ($package =~ m/LocaleTranslation/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package =~ /LocaleTranslation/) 0 0 0
14 0 ▶ $hash->{locale_id} = $hash->{parent}->id if $hash->{parent};
Branch: 1 branch
BranchTrueFalseTotal
if $hash->{"parent"} 0 0 0
15 }
16 0 return shift->SUPER::get_all(@_);
17 }
18  
19  
20 # Used for the login version.
21 # X-Shopify-Api-Features:pagination-headers, embed-metafields, include-image-token.
22 0 ▶sub embed_metafields { if (defined $_[1]) { $_[0]->{embed_metafields} = $_[1]; $_[0]->update_x_shopify_api_features; } return $_[0]->{embed_metafields}; }
Subroutine embed_metafields: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
23 0 ▶sub include_image_token { if (defined $_[1]) { $_[0]->{include_image_token} = $_[1]; $_[0]->update_x_shopify_api_features; } return $_[0]->{include_image_token}; }
Subroutine include_image_token: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
24 0 ▶sub pagination_headers { if (defined $_[1]) { $_[0]->{pagination_headers} = $_[1]; $_[0]->update_x_shopify_api_features; } return $_[0]->{pagination_headers}; }
Subroutine pagination_headers: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
25 0 ▶sub include_variant_summary { if (defined $_[1]) { $_[0]->{include_variant_summary} = $_[1]; $_[0]->update_x_shopify_api_features; } return $_[0]->{include_variant_summary}; }
Subroutine include_variant_summary: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
26 0 ▶sub include_gift_cards { if (defined $_[1]) { $_[0]->{include_gift_cards} = $_[1]; $_[0]->update_x_shopify_api_features; } return $_[0]->{include_gift_cards}; }
Subroutine include_gift_cards: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
27 0 ▶sub future_publishables { if (defined $_[1]) { $_[0]->{future_publishables} = $_[1]; $_[0]->update_x_shopify_api_features; } return $_[0]->{future_publishables}; }
Subroutine future_publishables: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
28  
29 sub x_shopify_api_headers {
30 0 ▶ $_[0]->embed_metafields($_[1]);
Subroutine x_shopify_api_headers: not called CC=1 SCAR=6.9
Pod undocumented
31 0 $_[0]->include_image_token($_[1]);
32 0 $_[0]->pagination_headers($_[1]);
33 0 $_[0]->include_variant_summary($_[1]);
34 0 $_[0]->include_gift_cards($_[1]);
35 0 $_[0]->future_publishables($_[1]);
36 }
37  
38 sub update_x_shopify_api_features {
39 0 ▶ my ($self) = @_;
Subroutine update_x_shopify_api_features: not called CC=10 SCAR=47.0
Pod undocumented
40 0 ▶ my @list = (
Branch: 6 branches
BranchTrueFalseTotal
$_[0]->embed_metafields ? : 0 0 0
$_[0]->pagination_headers ? : 0 0 0
$_[0]->include_image_token ? : 0 0 0
$_[0]->include_variant_summary ? : 0 0 0
$_[0]->include_gift_cards ? : 0 0 0
$_[0]->future_publishables ? : 0 0 0
41 ($_[0]->embed_metafields ? ('embed-metafields') : ()),
42 ($_[0]->pagination_headers ? ('pagination-headers') : ()),
43 ($_[0]->include_image_token ? ('include-image-token') : ()),
44 ($_[0]->include_variant_summary ? ('include-variant-summary') : ()),
45 ($_[0]->include_gift_cards ? ('include-gift-cards') : ()),
46 ($_[0]->future_publishables ? ('future-publishables') : ()),
47 );
48 0 ▶ if (int(@list) == 0 && $self->url_handler->{_default_headers}->{'X-Shopify-Api-Features'}) {
Branch: 2 branches
BranchTrueFalseTotal
if (int @list == 0 and $self->url_handler->{'_default_headers'}{'X-Shopify-Api-Features'}) { } 0 0 0
elsif (int @list > 0) { } 0 0 0
Condition0%0/3
int @list == 0 and $self->url_handler->{"_default_headers"}{"X-Shopify-Api-Features"}
!ll&&!rl&&r
000
MC/DC0%0/2
int @list == 0 and $self->url_handler->{"_default_headers"}{"X-Shopify-Api-Features"}
int @list == 0 $self->url_handler->{"_default_headers"}{"X-Shopify-Api-Features"}
Truth table0%0/3
A and B
A= int @list == 0B= $self->url_handler->{"_default_headers"}{"X-Shopify-Api-Features"}
ABresult
0X0
100
111
49 0 delete $self->url_handler->{_default_headers}->{'X-Shopify-Api-Features'};
50 0 delete $self->url_handler->{_default_headers}->{'X-Requested-With'};
51 } elsif (int(@list) > 0) {
52 0 $self->url_handler->{_default_headers}->{'X-Shopify-Api-Features'} = join(", ", @list);
53 0 $self->url_handler->{_default_headers}->{'X-Requested-With'} = "XMLHttpRequest";
54 }
55 }
56 # Takes in a list of locales.
57 sub create_update_locale_translation {
58 0 ▶ my ($self, @locales) = @_;
Subroutine create_update_locale_translation: not called CC=3 SCAR=24.8
Pod undocumented
59 0 my @english_translation = $self->get_english_translation;
60 0 my %hash = map { $_->english => $_->text } @locales;
61 0 my %mapping = ();
62 0 foreach my $english (@english_translation) {
63 0 ▶ $mapping{$english->id} = exists $hash{$english->english} ? $hash{$english->english} : "";
Branch: 1 branch
BranchTrueFalseTotal
exists $hash{$english->english} ? : 0 0 0
64 }
65 0 my $locale_id = $locales[0]->locale_id;
66 0 my ($decoded, $response) = $self->use_url('put', "/admin/locales/$locale_id.json", { s => \%mapping });
67 0 my $package = "WWW::Shopify::Model::Locale";
68 0 my $object = $package->from_json($decoded->{$package->singular}, $self);
69 0 return $object;
70 }
71  
72 sub get_english_translation {
73 0 ▶ my ($self) = @_;
Subroutine get_english_translation: not called CC=1 SCAR=6.9
Pod undocumented
74 0 my $package = "WWW::Shopify::Model::LocaleTranslation";
75 0 my ($decoded, $response) = $self->use_url('get', "/admin/locale_translations/english_translations.json");
76 0 return map { my $object = $package->from_json($_, $self); $object; } @{$decoded->{$package->plural}};
77 }
78  
79 sub create {
80 0 ▶ my ($self, $item, $hash) = @_;
Subroutine create: not called CC=2 SCAR=17.9
Pod documented
81 0 ▶ return shift->SUPER::create(@_) unless ref($item) =~ m/LocaleTranslation/;
Branch: 1 branch
BranchTrueFalseTotal
unless ref($item) =~ /LocaleTranslation/ 0 0 0
82 }
83  
84 sub send_activation_links {
85 0 ▶ my ($self, @customers) = @_;
Subroutine send_activation_links: not called CC=2 SCAR=17.9
Pod undocumented
86 0 my ($decoded, $response) = $self->use_url('put', "/admin/customers/set", { operation => "invite", 'customer_ids[]' => [map { $_->id } @customers] }, 1, "application/x-www-form-urlencoded");
87 0 ▶ die new WWW::Shopify::Exception("Unexpected Response.") unless $decoded->{message} =~ m/Invited (\d+) customer/;
Branch: 1 branch
BranchTrueFalseTotal
unless $decoded->{"message"} =~ /Invited (\d+) customer/ 0 0 0
88 0 return $1;
89 }
90  
91 sub get_activation_link {
92 0 ▶ my ($self, $customer) = @_;
Subroutine get_activation_link: not called CC=2 SCAR=17.9
Pod undocumented
93 0 my ($decoded, $reponse) = $self->use_url('get', "/admin/customers/" . $customer->id, { }, "text/html");
94 0 ▶ die new WWW::Shopify::Exception("Unable to find activation link for " . $customer->id . ".") unless $decoded =~ m/http:\/\/[\w\.]+\/account\/activate\/\w+/;
Branch: 1 branch
BranchTrueFalseTotal
unless $decoded =~ m[http://[\w\.]+/account/activate/\w+] 0 0 0
95 0 return $&;
96 }
97  
98 sub get_reset_token {
99 0 ▶ my ($self, $customer) = @_;
Subroutine get_reset_token: not called CC=2 SCAR=17.9
Pod undocumented
100 0 my ($decoded, $reponse) = $self->use_url('get', "/admin/customers/" . $customer->id, { }, "text/html");
101 0 ▶ die new WWW::Shopify::Exception("Unable to find activation link for " . $customer->id . ".") unless $decoded =~ m/http:\/\/[\w\.]+\/account\/activate\/(\w+)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $decoded =~ m[http://[\w\.]+/account/activate/(\w+)] 0 0 0
102 0 return $1;
103 }
104  
105 sub send_activation_link {
106 0 ▶ my ($self, $customer, $from, $subject, $body, $reset_token) = @_;
Subroutine send_activation_link: not called CC=1 SCAR=6.9
Pod undocumented
107 0 my ($decoded, $response) = $self->use_url('post', "/admin/customers/" . $customer->id . "/invite", {
108 utf => '✓',
109 source => 'adminnext',
110 'customer_invite_message[from]' => $from,
111 'customer_invite_message[subject]' => $subject,
112 'customer_invite_message[body]' => $body,
113 'customer_invite_message[reset_token]' => $reset_token
114 }, "application/x-www-form-urlencoded");
115 }
116  
117 1 1;
« blib/lib/WWW/Shopify.pm ↑ Summary blib/lib/WWW/Shopify/Model/LinkList/Link.pm »