| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | package WWW::Shopify::Model::NestedItem; | ||
| 7 | use parent 'WWW::Shopify::Model::Item'; | ||
| 8 | |||
| 9 | sub is_nested { return 1; } | ||
| 10 | # Has a parent object; default is the above package nest. | ||
| 11 | sub parent { my $package = $_[0]; $package = ref($package) if ref($package); die new WWW::Shopify::Exception($package) unless $package =~ m/(.*?)\:\:\w+$/; return $1 eq 'WWW::Shopify::Model' ? undef : $1; } | ||
| 12 | # Used to specify something that there's only ever one of. | ||
| 13 | sub is_single { 0; } | ||
| 14 | # Everything taken together on a nested item is an identifier, unless it's solo, in which case it's the parent id. | ||
| 15 | # Assumes that this will always be non-null. | ||
| 16 | sub identifier { | ||
| 17 | return 'id' if $_[0]->field('id'); | ||
| 18 | return map { $_->name } grep { $_->is_relation && $_->is_parent } values(%{$_[0]->fields}) if $_[0]->is_single; | ||
| 19 | return map { $_->name } grep { !$_->is_relation } values(%{$_[0]->fields}); | ||
| 20 | } | ||
| 21 | |||
| 22 | sub countable { return undef; } | ||
| 23 | sub gettable { return undef; } | ||
| 24 | sub creatable { return undef; } | ||
| 25 | sub updatable { return undef; } | ||
| 26 | sub deletable { return undef; } | ||
| 27 | |||
| 28 | 1 |