File Coverage

blib/lib/DS/TypeSpec/Field.pm
Criterion Covered Total %
statement 14 30 46.6
branch 0 8 0.0
condition n/a
subroutine 4 7 57.1
pod 0 3 0.0
total 18 48 37.5


line stmt bran cond sub pod time code
1             #!perl
2            
3             # ########################################################################## #
4             # Title: Field specification
5             # Creation date: 2007-03-05
6             # Author: Michael Zedeler
7             # Description: Class holding field specifications for data stream types
8             # File: $Source: /data/cvs/lib/DSlib/lib/DS/TypeSpec/Field.pm,v $
9             # Repository: kronhjorten
10             # State: $State: Exp $
11             # Documentation: inline
12             # Recepient: -
13             # ########################################################################## #
14            
15             package DS::TypeSpec::Field;
16            
17 12     12   68 use base qw{ Clone };
  12         26  
  12         1162  
18            
19 12     12   62 use strict;
  12         25  
  12         347  
20 12     12   62 use Carp::Assert;
  12         22  
  12         96  
21            
22             our ($VERSION) = $DS::VERSION;
23             our ($REVISION) = '$Revision: 1.1 $' =~ /(\d+\.\d+)/;
24            
25            
26             sub new {
27 51     51 0 12401 my( $class, $name ) = @_;
28            
29 51         236 assert( $name =~ /^\S+/);
30 51         262 my $self = {
31             name => $name
32             };
33 51         120 bless $self, $class;
34            
35 51         283 return $self;
36             }
37            
38             # Validator receives this object and the data to validate
39             sub validator {
40 0     0 0   my( $self, $validator ) = @_;
41            
42 0           my $result = 1;
43 0 0         if( $validator ) {
44 0           my $new_validator;
45 0 0         if( ref( $validator ) eq 'Regexp' ) {
46             $self->{validator} = sub {
47 0     0     $_[1] =~ /$validator/;
48 0           };
49             } else {
50 0           $self->{validator} = $validator;
51             }
52             } else {
53 0           $result = $self->{validator};
54             }
55 0           return $result;
56             }
57            
58             sub undef_ok {
59 0     0 0   my( $self, $undef_ok ) = @_;
60            
61 0           my $result = 1;
62 0 0         if( $undef_ok ) {
63 0 0         $self->{undef_ok} = $undef_ok ? 1 : 0;
64             } else {
65 0           $undef_ok = $self->{undef_ok};
66             }
67 0           return $result;
68             }
69            
70             1;