File: Validate.pm

package info (click to toggle)
libobject-lazy-perl 0.16-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 212 kB
  • sloc: perl: 1,065; makefile: 2
file content (125 lines) | stat: -rw-r--r-- 2,574 bytes parent folder | download | duplicates (2)
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
package Object::Lazy::Validate; ## no critic (TidyCode)

use strict;
use warnings;

our $VERSION = '0.12';

use Params::Validate qw(:all);

sub validate_new { ## no critic (ArgUnpacking)
    return validate_with(
        params => \@_,
        spec   => [
            {type => SCALAR},
            {type => CODEREF | HASHREF},
        ],
        stack_skip => 1,
    );
}

# check and modify params
sub init {
    my $params = shift;

    if (ref $params eq 'CODE') {
        $params = {
            build => $params,
        };
    }

    return validate_with(
        params => $params,
        spec   => {
            build        => {type => CODEREF},
            isa          => {type => SCALAR | ARRAYREF, default => []},
            DOES         => {type => SCALAR | ARRAYREF, default => []},
            VERSION      => {type => SCALAR | OBJECT, optional => 1},
            version_from => {type => SCALAR, optional => 1},
            logger       => {type => CODEREF, optional => 1},
            ref          => {
                type      => SCALAR,
                optional  => 1,
                callbacks => {
                    'depends use Object::Lazy::Ref' => sub {
                        $Object::Lazy::Ref::VERSION;
                    }
                }
            },
        },
        called => 'the 2nd parameter hashref',
    );
};

# $Id$

1;

__END__

=pod

=head1 NAME

Object::Lazy::Validate - validator and initializer for Object::Lazy

=head1 VERSION

0.12

=head1 SYNOPSIS

    use Object::Lazy::Validate;

    my ($class, $params) = Object::Lazy::Validate::validate_new(@_);

    $params = Object::Lazy::Validate::init($params);

=head1 DESCRIPTION

Validator and initializer for Object::Lazy

=head1 SUBROUTINES/METHODS

=head2 sub validate_new

Validator for the constructor of the package Object::Lazy.

=head2 sub init

Initializer for the constructor of the package ObjectLazy.

=head1 DIAGNOSTICS

Validator and initializer can confess at false parameters.

=head1 CONFIGURATION AND ENVIRONMENT

nothing

=head1 DEPENDENCIES

L<Params::Validate|Params::Validate>

=head1 INCOMPATIBILITIES

not known

=head1 BUGS AND LIMITATIONS

not known

=head1 AUTHOR

Steffen Winkler

=head1 LICENSE AND COPYRIGHT

Copyright (c) 2007 - 2012,
Steffen Winkler
C<< <steffenw at cpan.org> >>.
All rights reserved.

This module is free software;
you can redistribute it and/or modify it
under the same terms as Perl itself.