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 =attribute_private DEBUG
10 Debugging warnings can be enabled by setting the environment variable
11 DATA_DPATH_VALIDATOR_DEBUG to a true value.
15 use constant DEBUG => $ENV{DATA_DPATH_VALIDATOR_DEBUG} || 0;
17 around visit_array => sub
19 my ($orig, $self, $array) = @_;
21 warn 'ARRAY: '. $self->current_template if DEBUG;
22 if(@$array == 1 && $array->[0] eq '*')
24 $self->append_text('[reftype eq "HASH" ]');
25 $self->add_template($self->current_template);
29 if($self->current_template =~ /\/$/)
31 my $temp = $self->current_template;
32 $self->reset_template();
34 $self->append_text($temp);
43 # to make release-unused-vars.t happy
44 #my ($self, $elem, $index, $array) = @_;
45 my ($self, $elem) = @_;
47 warn 'ARRAYENTRY: '. $self->current_template if DEBUG;
50 $self->append_text($elem . '/*');
51 $self->add_template($self->current_template);
53 elsif(ref($elem) eq 'HASH')
58 $self->value_type('NONE');
61 around visit_hash => sub
63 my ($orig, $self, $hash) = @_;
65 if($self->current_template =~ /\/$/)
67 my $temp = $self->current_template;
68 $self->reset_template();
70 $self->append_text($temp);
72 warn 'HASH: '. $self->current_template if DEBUG;
77 around visit_value => sub
79 my ($orig, $self, $val) = @_;
81 if($self->value_type eq 'NONE')
84 $self->append_text($val . '/*');
85 $self->add_template($self->current_template);
86 warn 'VALUE: ' . $self->current_template if DEBUG;
89 elsif($self->value_type eq 'HashKey')
91 $self->append_text($val);
92 warn 'VALUE: ' . $self->current_template if DEBUG;
102 __PACKAGE__->meta->make_immutable;