1 package Catalyst::Controller::DBIC::API::Validator::Visitor;
2 #ABSTRACT: Provides validation services for inbound requests against whitelisted parameters
4 use namespace::autoclean;
6 BEGIN { extends 'Data::DPath::Validator::Visitor'; }
8 use constant DEBUG => $ENV{DATA_DPATH_VALIDATOR_DEBUG} || 0;
10 around visit_array => sub
12 my ($orig, $self, $array) = @_;
14 warn 'ARRAY: '. $self->current_template if DEBUG;
15 if(@$array == 1 && $array->[0] eq '*')
17 $self->append_text('[reftype eq "HASH" ]');
18 $self->add_template($self->current_template);
22 if($self->current_template =~ /\/$/)
24 my $temp = $self->current_template;
25 $self->reset_template();
27 $self->append_text($temp);
36 my ($self, $elem, $index, $array) = @_;
38 warn 'ARRAYENTRY: '. $self->current_template if DEBUG;
41 $self->append_text($elem . '/*');
42 $self->add_template($self->current_template);
44 elsif(ref($elem) eq 'HASH')
49 $self->value_type('NONE');
52 around visit_hash => sub
54 my ($orig, $self, $hash) = @_;
56 if($self->current_template =~ /\/$/)
58 my $temp = $self->current_template;
59 $self->reset_template();
61 $self->append_text($temp);
63 warn 'HASH: '. $self->current_template if DEBUG;
68 around visit_value => sub
70 my ($orig, $self, $val) = @_;
72 if($self->value_type eq 'NONE')
75 $self->append_text($val . '/*');
76 $self->add_template($self->current_template);
77 warn 'VALUE: ' . $self->current_template if DEBUG;
80 elsif($self->value_type eq 'HashKey')
82 $self->append_text($val);
83 warn 'VALUE: ' . $self->current_template if DEBUG;
93 __PACKAGE__->meta->make_immutable;