File: MaxSize.pm

package info (click to toggle)
libbadger-perl 0.16-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,400 kB
  • sloc: perl: 11,004; makefile: 9
file content (71 lines) | stat: -rw-r--r-- 1,536 bytes parent folder | download
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
package Badger::Data::Facet::List::MaxSize;

use Badger::Data::Facet::Class
    version   => 0.01,
    type      => 'list',
    args      => 'max_size';


sub validate {
    my ($self, $value, $type) = @_;

    return scalar(@$value) <= $self->{ max_size }
        ? $value
        : $self->invalid_msg( 
            too_many => $type || 'List', $self->{ max_size }, scalar(@$value) 
          );

}

1;

__END__

=head1 NAME

Badger::Data::Facet::List::MaxSize - validation facet for the size of a list

=head1 DESCRIPTION

This module implements a validation facets that checks the size of a list
to assert that it is equal to or above a certain size in terms of items it
contains.

=head1 METHODS

This module implement the following method in addition to those inherited from
the L<Badger::Data::Facet::List>, L<Badger::Data::Facet> and L<Badger::Base>
base classes.

=head2 validate($list_ref, $type)

This method validates that the size of the list (i.e. number of elements)
passed by reference as the first  argument is less than or equal to the pre-
defined maximum limit.

=head1 AUTHOR

Andy Wardley L<http://wardley.org/>

=head1 COPYRIGHT

Copyright (C) 2008-2012 Andy Wardley.  All Rights Reserved.

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

=head1 SEE ALSO

L<Badger::Base>,
L<Badger::Data::Facet>,
L<Badger::Data::Facet::List>.

=cut

# Local Variables:
# mode: perl
# perl-indent-level: 4
# indent-tabs-mode: nil
# End:
#
# vim: expandtab shiftwidth=4: