1 package Catalyst::Controller::DBIC::API::Validator::Visitor;
3 #ABSTRACT: Provides validation services for inbound requests against whitelisted parameters
5 use namespace::autoclean;
7 BEGIN { extends 'Data::DPath::Validator::Visitor'; }
9 =attribute_private DEBUG
11 Debugging warnings can be enabled by setting the environment variable
12 DATA_DPATH_VALIDATOR_DEBUG to a true value.
16 use constant DEBUG => $ENV{DATA_DPATH_VALIDATOR_DEBUG} || 0;
18 around visit_array => sub {
19 my ( $orig, $self, $array ) = @_;
21 warn 'ARRAY: ' . $self->current_template if DEBUG;
22 if ( @$array == 1 && $array->[0] eq '*' ) {
23 $self->append_text('[reftype eq "HASH" ]');
24 $self->add_template( $self->current_template );
27 if ( $self->current_template =~ /\/$/ ) {
28 my $temp = $self->current_template;
29 $self->reset_template();
31 $self->append_text($temp);
38 sub visit_array_entry {
40 # to make release-unused-vars.t happy
41 #my ($self, $elem, $index, $array) = @_;
42 my ( $self, $elem ) = @_;
44 warn 'ARRAYENTRY: ' . $self->current_template if DEBUG;
46 $self->append_text( $elem . '/*' );
47 $self->add_template( $self->current_template );
49 elsif ( ref($elem) eq 'HASH' ) {
53 $self->value_type('NONE');
56 around visit_hash => sub {
57 my ( $orig, $self, $hash ) = @_;
59 if ( $self->current_template =~ /\/$/ ) {
60 my $temp = $self->current_template;
61 $self->reset_template();
63 $self->append_text($temp);
65 warn 'HASH: ' . $self->current_template if DEBUG;
70 around visit_value => sub {
71 my ( $orig, $self, $val ) = @_;
73 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' ) {
81 $self->append_text($val);
82 warn 'VALUE: ' . $self->current_template if DEBUG;
90 __PACKAGE__->meta->make_immutable;