| 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 | ▶ | use base qw{ Clone }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | 12 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 12 | ▶ | use Carp::Assert; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | 12 | our ($VERSION) = $DS::VERSION; | |||||||||
| 23 | 12 | our ($REVISION) = '$Revision: 1.1 $' =~ /(\d+\.\d+)/; | |||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | 51 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 27 | 51 | my( $class, $name ) = @_; | |||||||||
| 28 | |||||||||||
| 29 | 51 | assert( $name =~ /^\S+/); | |||||||||
| 30 | 51 | my $self = { | |||||||||
| 31 | name => $name | ||||||||||
| 32 | }; | ||||||||||
| 33 | 51 | bless $self, $class; | |||||||||
| 34 | |||||||||||
| 35 | 51 | return $self; | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | # Validator receives this object and the data to validate | ||||||||||
| 39 | 0 | ▶ | sub validator { | ||||||||
|
Subroutine
validator: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 40 | 0 | my( $self, $validator ) = @_; | |||||||||
| 41 | |||||||||||
| 42 | 0 | my $result = 1; | |||||||||
| 43 | 0 | ▶ | if( $validator ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | my $new_validator; | |||||||||
| 45 | 0 | ▶ | if( ref( $validator ) eq 'Regexp' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 0 | ▶ | $self->{validator} = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 47 | 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 | 0 | ▶ | sub undef_ok { | ||||||||
|
Subroutine
undef_ok: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 59 | 0 | my( $self, $undef_ok ) = @_; | |||||||||
| 60 | |||||||||||
| 61 | 0 | my $result = 1; | |||||||||
| 62 | 0 | ▶ | if( $undef_ok ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | ▶ | $self->{undef_ok} = $undef_ok ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | } else { | ||||||||||
| 65 | 0 | $undef_ok = $self->{undef_ok}; | |||||||||
| 66 | } | ||||||||||
| 67 | 0 | return $result; | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 12 | 1; | |||||||||