File: tmp

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 (51 lines) | stat: -rw-r--r-- 1,447 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
#-----------------------------------------------------------------------
# any - text must match one of a pre-defined set of values
# TODO: change name to 'any'.  Should we accept facets and make a 
# literal match a facet too?
#-----------------------------------------------------------------------

package Badger::Data::Facet::Any;

use Badger::Class
    base      => 'Badger::Data::Facet',
    constants => 'ARRAY';


sub init {
    my ($self, $config) = @_;
    
    $self->SUPER::init($config);

    # TODO: should we updgrade these to facets? (prolly)

    # ensure value is folded to a list reference
    my $value = $self->{ value };
    $self->{ values } = 
        ref $value eq ARRAY
            ?  $value
            : [$value];

    return $self
}

sub validate {
    my ($self, $value, $type) = @_;
    
    # TODO: should we worry about numerical comparisons?  In the original
    # context of XML::Schema there was no need because all data originates
    # from text documents and a text comparison is what defined equality.
    # (e.g. 1.0 is not the same as 1)
    foreach my $expect (@{ $self->{ values } }) {
        return $value
            if $value eq $expect;
    }

    return $self->invalid_msg( not_any => $type || 'Text', $self->{ values }, $value );
}



#-----------------------------------------------------------------------
# whitespace
#-----------------------------------------------------------------------