| 1 | # vim: sw=4 ts=4 ft=perl | ||||||||||
| 2 | |||||||||||
| 3 | package # hide from pause | ||||||||||
| 4 | WebService::Braintree::Role::AdvancedSearch; | ||||||||||
| 5 | |||||||||||
| 6 | 22 | ▶ | use 5.010_001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 22 | ▶ | use strictures 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 22 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 22 | ▶ | use WebService::Braintree::AdvancedSearchNodes; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 22 | ▶ | use WebService::Braintree::Util qw(is_arrayref); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 2559 | ▶ | sub field { | ||||||||
|
Subroutine
field: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 15 | 2559 | my $class = shift; | |||||||||
| 16 | 2559 | my ($proto, $name) = @_; | |||||||||
| 17 | |||||||||||
| 18 | 2559 | push @{$class->FIELDS}, $name; | |||||||||
| 19 | |||||||||||
| 20 | 2559 | my $default; | |||||||||
| 21 | 2559 | ▶ | if (ref $proto) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 486 | $default = $proto | |||||||||
| 23 | } | ||||||||||
| 24 | else { | ||||||||||
| 25 | 2073 | my $node_class = "WebService::Braintree::${proto}"; | |||||||||
| 26 | 85 | ▶ | $default = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 85 | return $node_class->new( | |||||||||
| 28 | searcher => shift, | ||||||||||
| 29 | name => $name, | ||||||||||
| 30 | ); | ||||||||||
| 31 | 2073 | }; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 2559 | $class->can('has')->($name => ( | |||||||||
| 35 | is => 'rw', | ||||||||||
| 36 | default => $default, | ||||||||||
| 37 | )); | ||||||||||
| 38 | |||||||||||
| 39 | 2559 | return; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 67 | ▶ | sub equality_field { shift->field(EqualityNode => @_) } | ||||||||
|
Subroutine
equality_field: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 43 | 22 | ▶ | sub is_field { shift->field(IsNode => @_) } | ||||||||
|
Subroutine
is_field: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 44 | 23 | ▶ | sub key_value_field { shift->field(KeyValueNode => @_) } | ||||||||
|
Subroutine
key_value_field: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 45 | 66 | ▶ | sub partial_match_field { shift->field(PartialMatchNode => @_) } | ||||||||
|
Subroutine
partial_match_field: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 46 | 441 | ▶ | sub range_field { shift->field(RangeNode => @_) } | ||||||||
|
Subroutine
range_field: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 47 | 1454 | ▶ | sub text_field { shift->field(TextNode => @_) } | ||||||||
|
Subroutine
text_field: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 48 | |||||||||||
| 49 | 486 | ▶ | sub multiple_values_field { | ||||||||
|
Subroutine
multiple_values_field: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 50 | 486 | my ($class, $name, @allowed_values) = @_; | |||||||||
| 51 | @allowed_values = map { | ||||||||||
| 52 | 486 | ▶ | is_arrayref($_) ? @$_ : $_ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | } @allowed_values; | ||||||||||
| 54 | |||||||||||
| 55 | 34 | ▶ | my $node = sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 56 | 34 | ▶ | return WebService::Braintree::MultipleValuesNode->new( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | searcher => shift, | ||||||||||
| 58 | name => $name, | ||||||||||
| 59 | allowed_values => @allowed_values ? [@allowed_values] : undef, | ||||||||||
| 60 | ); | ||||||||||
| 61 | 486 | }; | |||||||||
| 62 | 486 | $class->field($node => $name); | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 14 | ▶ | sub to_hash { | ||||||||
|
Subroutine
to_hash: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 66 | 14 | my ($self) = @_; | |||||||||
| 67 | 14 | my $class = ref($self); | |||||||||
| 68 | |||||||||||
| 69 | my %hash = map { | ||||||||||
| 70 | 13 | $_ => $self->$_->criteria | |||||||||
| 71 | } grep { | ||||||||||
| 72 | 98 | $self->$_->active | |||||||||
| 73 | 14 | } @{$class->FIELDS}; | |||||||||
| 74 | |||||||||||
| 75 | 14 | return \%hash; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 22 | 1; | |||||||||
| 79 | __END__ | ||||||||||