This file is indexed.

/usr/share/perl5/Validation/Class/Plugins.pod is in libvalidation-class-perl 3.1.1-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
=head1 NAME

Validation::Class::Plugins - Basic Instructions for Writing Plugins

=head1 DESCRIPTION

This documentation serves as a brief overview on writing plugins for
Validation::Class. Here are the key points:

L<Validation::Class> is written with L<Moose> and a plugin must be designed
as a L<Moose::Role>. As a role the plugins attributes and methods are imported
into the calling class and because of this it is important to name your
attributes and methods cautiously as to not overwrite another plugins
functionality.

When creating B<official> Validation::Class plugins you should use the namespace
Validation::Class::Plugin::YourPluginName. This will allow users of your plugin
to simply pass YourPluginName to the load_plugins() method. Otherwise you will
need to pass the fully-qualified plugin package name prefixed with a "+" symbol.
The following is an example of including a plugin.

    package MyApp::Validation;
    
    use Validation::Class;
        load_plugins __PACKAGE__,
            'YourPluginName',
            '+MyApp::Validation::YourPluginName';
    
    # a validation rule
    field 'login'  => {
        label      => 'User Login',
        error      => 'Login invalid.',
        required   => 1,
        validation => sub {
            my ($self, $this_field, $all_params) = @_;
            return $this_field->{value} eq 'admin' ? 1 : 0;
        }
    };
    
    # a validation rule
    field 'password'  => {
        label         => 'User Password',
        error         => 'Password invalid.',
        required      => 1,
        validation    => sub {
            my ($self, $this_field, $all_params) = @_;
            return $this_field->{value} eq 'pass' ? 1 : 0;
        }
    };
    
    1;
    
Your plugin is loaded at runtime and can manipulate the L<Validation::Class>
object by declaring a B<new> method. The following is an example of a fictitious
plugin for formatting telephone numbers:

    package Validation::Class::Plugin::TelephoneFormatting;
    
    use Moose::Role;
    
    # hook into the instantiation process
    # of the calling class at runtime
    sub new {
        my ($class, $self) = @_;
        
        # US Telephones
        $class->filters->{telephone_usa} = sub {
            my $phone = shift;
               $phone =~ s/\D//g;
            
            my ($area, $prefix, $xchng) = $phone =~ m/1?(\d{3})(\d{3})(\d{4});
               
            return "+1 ($area) $prefix-$xchng";
        };
        
    }

Once we create, test and deploy our plugin, we can use it in our code as follows:
    
    package MyApp::Validation;
    
    use Validation::Class;
    
    __PACKAGE__->load_plugins('TelephoneFormatting');
    
    # a validation rule
    field 'phone'  => {
        label      => 'Telephone Number',
        error      => 'Phone number invalid.',
        required   => 1,
        filters    => 'telephone_usa',
        filtering  => 'post',
        pattern    => '+1 (###) ###-####'
    };
    
    package main ;
    
    my $rules = MyApp::Validation->new(...);
    
    # ...
    
=head1 AUTHOR

Al Newkirk <awncorp@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by awncorp.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
    
=cut