Shopify/Model/Product.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 20 Podpod 0.0% 0 / 13 totaltotal 0.0% 0 / 93 CC 1 SCAR 6.9
CC
1
Cov
0%
fields
2.0
BEGIN
2.0
queries
2.0
CRAP 2.0
1 #!/usr/bin/perl
2  
3 use strict;
4 use warnings;
5  
6 use WWW::Shopify;
7 use WWW::Shopify::Model::Product::Image;
8 use WWW::Shopify::Model::Product::Option;
9 use WWW::Shopify::Model::Product::Variant;
10  
11 package WWW::Shopify::Model::Product;
12 use parent "WWW::Shopify::Model::Item";
13  
14 my $fields; sub fields { return $fields; }
15 BEGIN { $fields = {
16 "body_html" => new WWW::Shopify::Field::Text::HTML(),
17 "variants" => new WWW::Shopify::Field::Relation::Many("WWW::Shopify::Model::Product::Variant", 1),
18 "handle" => new WWW::Shopify::Field::String::Handle(),
19 "product_type" => new WWW::Shopify::Field::String(),
20 "template_suffix" => new WWW::Shopify::Field::String(),
21 "published_scope" => new WWW::Shopify::Field::String(),
22 "title" => new WWW::Shopify::Field::String(),
23 "vendor" => new WWW::Shopify::Field::String(),
24 "tags" => new WWW::Shopify::Field::String::Words(0,'*',', '),
25 "images" => new WWW::Shopify::Field::Relation::Many("WWW::Shopify::Model::Product::Image"),
26 # Useless alias.
27 # "image" => new WWW::Shopify::Field::Relation::OwnOne("WWW::Shopify::Model::Product::Image"),
28 "options" => new WWW::Shopify::Field::Relation::Many("WWW::Shopify::Model::Product::Option", 1, 3),
29 "metafields" => new WWW::Shopify::Field::Relation::Many("WWW::Shopify::Model::Metafield"),
30 "id" => new WWW::Shopify::Field::Identifier(),
31 "created_at" => new WWW::Shopify::Field::Date(),
32 "published_at" => new WWW::Shopify::Field::Date(),
33 "published" => new WWW::Shopify::Field::Boolean(),
34 "updated_at" => new WWW::Shopify::Field::Date(),
35 "status" => new WWW::Shopify::Field::String::Enum(["draft","active","archived"]) #this isn't 'working' yet, so we will leave it out for now.
36 };
37 }
38 my $queries; sub queries { return $queries; }
39 BEGIN { $queries = {
40 created_at_min => new WWW::Shopify::Query::LowerBound('created_at'),
41 created_at_max => new WWW::Shopify::Query::UpperBound('created_at'),
42 updated_at_min => new WWW::Shopify::Query::LowerBound('updated_at'),
43 updated_at_max => new WWW::Shopify::Query::UpperBound('updated_at'),
44 published_at_min => new WWW::Shopify::Query::LowerBound('published_at'),
45 published_at_max => new WWW::Shopify::Query::UpperBound('published_at'),
46 ids => new WWW::Shopify::Query::MultiMatch('id'),
47 published_status => new WWW::Shopify::Query::Enum('published_status', ['unpublished', 'published', 'any']),
48 product_type => new WWW::Shopify::Query::Match('product_type'),
49 vendor => new WWW::Shopify::Query::Match('vendor'),
50 handle => new WWW::Shopify::Query::Match('handle'),
51 collection_id => new WWW::Shopify::Query::Custom("collection_id", sub {
52 my ($rs, $value) = @_;
53 return $rs->search({ 'collection_id' => $value },
54 { 'join' => 'collects','+select' => ['collects.collection_id'], '+as' => ['collection_id'], }
55 );
56 }),
57 since_id => new WWW::Shopify::Query::LowerBound('id')
58 }; }
59  
60  
61 sub get_fields { return grep { $_ ne "collects" && $_ ne "published" } keys(%$fields); }
62 sub creation_minimal { return qw(title); }
63 sub creation_filled { return qw(id created_at); }
64 # Odd, even without an update method, it still has an updated at.
65 sub update_filled { return qw(updated_at); }
66 sub update_fields { return qw(metafields handle product_type title template_suffix vendor tags images options body_html variants published_at published); }
67 sub throws_webhooks { return 1; }
68 sub get_order { ({'asc' => 'title' }, { 'desc' => 'id' }) }
69  
70 sub read_scope { return "read_products"; }
71 sub write_scope { return "write_products"; }
72  
73 eval(__PACKAGE__->generate_accessors); die $@ if $@;
74  
75 1