This file is indexed.

/usr/share/perl5/Catalyst/ActionRole/QueryMatching.pm is in libcatalyst-perl 5.90115-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package Catalyst::ActionRole::QueryMatching;

use Moose::Role;
use Moose::Util::TypeConstraints ();

requires 'match', 'match_captures', 'list_extra_info';

sub _query_attr { @{shift->attributes->{Query}||[]} }

has is_slurpy => (
  is=>'ro',
  init_arg=>undef,
  isa=>'Bool',
  required=>1,
  lazy=>1,
  builder=>'_build_is_slurpy');

  sub _build_is_slurpy {
    my $self = shift;
    my($query, @extra) = $self->_query_attr;
    return $query =~m/^.+,\.\.\.$/ ? 1:0;
  }

has query_constraints => (
  is=>'ro',
  init_arg=>undef,
  isa=>'ArrayRef|Ref',
  required=>1,
  lazy=>1,
  builder=>'_build_query_constraints');

  sub _build_query_constraints {
    my $self = shift;
    my ($constraint_proto, @extra) = $self->_query_attr;
    
    die "Action ${\$self->private_path} defines more than one 'Query' attribute" if scalar @extra;
    return +{} unless defined($constraint_proto);

    $constraint_proto =~s/^(.+),\.\.\.$/$1/; # slurpy is handled elsewhere
    
    # Query may be a Hash like Query(p=>Int,q=>Str) OR it may be a Ref like
    # Query(Tuple[p=>Int, slurpy HashRef]).  The only way to figure is to eval it
    # and look at what we have.
    my @signature = eval "package ${\$self->class}; $constraint_proto"
      or die "'$constraint_proto' is not valid Query Contraint at action ${\$self->private_path}, error '$@'";

    if(scalar(@signature) > 1) {
      # Do a dance to support old school stringy types
      # At this point we 'should' have a hash...
      my %pairs = @signature;
      foreach my $key(keys %pairs) {
        next if ref $pairs{$key};
        $pairs{$key} = Moose::Util::TypeConstraints::find_or_parse_type_constraint($pairs{$key}) ||
          die "'$pairs{$key}' is not a valid type constraint in Action ${\$self->private_path}";
      }
      return \%pairs;
    } else {
      # We have a 'reference type' constraint, like Dict[p=>Int,...]
      return $signature[0] if ref($signature[0]); # Is like Tiny::Type
      return Moose::Util::TypeConstraints::find_or_parse_type_constraint($signature[0]) ||
          die "'$signature[0]' is not a valid type constraint in Action ${\$self->private_path}";
    }
  }

around ['match','match_captures'] => sub {
    my ($orig, $self, $c, @args) = @_;
    my $tc = $self->query_constraints;
    if(ref $tc eq 'HASH') {
      # Do the key names match, unless slurpy?
      unless($self->is_slurpy) {
        return 0 unless $self->_compare_arrays([sort keys %$tc],[sort keys %{$c->req->query_parameters}]);
      }
      for my $key(keys %$tc) {
        $tc->{$key}->check($c->req->query_parameters->{$key}) || return 0;
      }
    } else {
      $tc->check($c->req->query_parameters) || return 0;
    }

    return $self->$orig($c, @args);
};

around 'list_extra_info' => sub {
  my ($orig, $self, @args) = @_;
  return {
    %{ $self->$orig(@args) }, 
  };
};

sub _compare_arrays {
  my ($self, $first, $second) = @_;
  no warnings;  # silence spurious -w undef complaints
  return 0 unless @$first == @$second;
  for (my $i = 0; $i < @$first; $i++) {
    return 0 if $first->[$i] ne $second->[$i];
  }
  return 1;
}

1;

=head1 NAME

Catalyst::ActionRole::QueryMatching - Match on GET parameters using type constraints

=head1 SYNOPSIS

    TBD

=head1 DESCRIPTION

    TBD

=head1 METHODS

This role defines the following methods

=head2 TBD

    TBD

=head1 AUTHORS

Catalyst Contributors, see Catalyst.pm

=head1 COPYRIGHT

This library is free software. You can redistribute it and/or modify it under
the same terms as Perl itself.

=cut