| 1 | 1 | ▶ | use 5.008; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | package Class::Value::Contact::Name::Full; | ||
| 6 | our $VERSION = '1.100840'; | ||
| 7 | # ABSTRACT: Contact-related value objects | ||
| 8 | 1 | ▶ | use parent 'Class::Value::Contact'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | # A name is well-formed if it consists of 2-5 whitespace-separated words, at | ||
| 11 | # least two of which must contain at least two [A-Za-z] characters. This is | ||
| 12 | # rather arbitrary; if you allow different forms of names, subclass this | ||
| 13 | # class. | ||
| 14 | # | ||
| 15 | # Note that we don't check whether the string only consists of valid | ||
| 16 | # characters - that's handled by the charset handler mechanism in | ||
| 17 | # Class::Value::String (i.e., when checking for the validity of the value - | ||
| 18 | # here we check for well-formedness). | ||
| 19 | sub is_well_formed_value { | ||
| 20 | my ($self, $value) = @_; | ||
| 21 | return 1 unless defined($value) && length($value); | ||
| 22 | return 0 unless $self->SUPER::is_well_formed_value($value); | ||
| 23 | local $_ = $value; | ||
| 24 | my @words = split /\s+/; | ||
| 25 | return 0 if @words < 2 || @words > 5; | ||
| 26 | my $valid_words = 0; | ||
| 27 | for (@words) { | ||
| 28 | $valid_words++ if 2 <= (() = /[A-Za-z]/g); | ||
| 29 | } | ||
| 30 | return $valid_words >= 2; | ||
| 31 | } | ||
| 32 | |||
| 33 | sub send_notify_value_not_wellformed { | ||
| 34 | my ($self, $value) = @_; | ||
| 35 | local $Error::Depth = $Error::Depth + 2; | ||
| 36 | $self->exception_container->record( | ||
| 37 | 'Class::Value::Contact::Exception::Name::NotWellformed', | ||
| 38 | name => $value,); | ||
| 39 | } | ||
| 40 | |||
| 41 | sub send_notify_value_invalid { | ||
| 42 | my ($self, $value) = @_; | ||
| 43 | local $Error::Depth = $Error::Depth + 2; | ||
| 44 | $self->exception_container->record( | ||
| 45 | 'Class::Value::Contact::Exception::Name::Invalid', | ||
| 46 | name => $value,); | ||
| 47 | } | ||
| 48 | 1; | ||
| 49 | |||
| 50 | |||
| 51 | __END__ | ||