Class::Value::String - String value object with length and character set checking


Class-Value documentation Contained in the Class-Value distribution.

Index


Code Index:

NAME

Top

Class::Value::String - String value object with length and character set checking

VERSION

Top

version 1.100840

DESCRIPTION

Top

This is a value object for strings. It can check for string length and character set restrictions.

METHODS

Top

charset_handler

Returns the character set handler for this value object. This method asks the value object's string_delegate() to get a character set handler. The character set handler needs to have an is_valid_string() method.

is_valid_normalized_value

In additional to the checks of this class' superclass, this method also asks is_valid_string_value().

is_valid_string_value

This method verifies that the argument value is not longer than the allowed maximum length and that the value object's character set handler says that it is a valid string.

max_length

Returns the maximum string length for this value object. This method asks the value object's string_delegate() to get the maximum length.

INSTALLATION

Top

See perlmodinstall for information and options on installing Perl modules.

BUGS AND LIMITATIONS

Top

No bugs have been reported.

Please report any bugs or feature requests through the web interface at http://rt.cpan.org/Public/Dist/Display.html?Name=Class-Value.

AVAILABILITY

Top

The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit http://www.perl.com/CPAN/ to find a CPAN site near you, or see http://search.cpan.org/dist/Class-Value/.

The development version lives at http://github.com/hanekomu/Class-Value/. Instead of sending patches, please fork this project using the standard git and github infrastructure.

AUTHOR

Top

  Marcel Gruenauer <marcel@cpan.org>

COPYRIGHT AND LICENSE

Top


Class-Value documentation Contained in the Class-Value distribution.

use 5.008;
use strict;
use warnings;

package Class::Value::String;
our $VERSION = '1.100840';
# ABSTRACT: String value object with length and character set checking
use parent 'Class::Value';
__PACKAGE__->mk_class_scalar_accessors(qw(string_delegate));
use constant HYGIENIC => ('string_delegate');

sub charset_handler {
    my $self = shift;

    # Do we even have a delegate from which we can get the information?
    my $string_delegate = $self->string_delegate;
    return
      unless ref($string_delegate)
          && UNIVERSAL::can($string_delegate, 'get_charset_handler_for');
    $string_delegate->get_charset_handler_for($self);
}

sub max_length {
    my $self = shift;

    # Do we even have a delegate from which we can get the information?
    my $string_delegate = $self->string_delegate;
    return 0
      unless ref($string_delegate)
          && UNIVERSAL::can($string_delegate, 'get_max_length_for');
    $string_delegate->get_max_length_for($self);
}

sub is_valid_normalized_value {
    my ($self, $value) = @_;
    return 0 unless $self->SUPER::is_valid_normalized_value($value);
    $self->is_valid_string_value($value);
}

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

    # string can be undef
    return 1 unless defined($value) && length($value);
    $self->max_length && return 0 if length($value) > $self->max_length;
    local $_ = $self->charset_handler;
    return 1 unless ref $_ && $_->can('is_valid_string');
    $_->is_valid_string($value);
}
1;


__END__