NAME

Persistent::DataType::VarChar - A Variable Length Character String Class


SYNOPSIS

  use Persistent::DataType::VarChar;
  use English;

  eval {  ### in case an exception is thrown ###

    ### allocate a string ###
    my $string = new Persistent::DataType::VarChar($value,
                                                   $max_length);

    ### get/set value of string ###
    $value = $string->value($new_value);

    ### get length of string ###
    my $length = $string->length();

    ### get/set maximum length of string ###
    my $max = $string->max_length($new_max);

    ### returns 'eq' for strings ###
    my $cmp_op = $string->get_compare_op();
  };

  if ($EVAL_ERROR) {  ### catch those exceptions! ###
    print "An error occurred: $EVAL_ERROR\n";
  }


ABSTRACT

This is a variable length character string class used by the Persistent framework of classes to implement the attributes of objects. This class provides methods for accessing the value, length, maximum length, and comparison operator of a variable length character string. A variable length string (VarChar) always has a finite maximum length that can not be exceeded. This is different from a character string (String) which can have an unlimited maximum length.

This class is usually not invoked directly, at least not when used with the Persistent framework of classes. However, the constructor arguments of this class are usually of interest when defining the attributes of a Persistent object since the add_attribute method of the Persistent classes instantiates this class directly. Also, the arguments to the value method are of interest when dealing with the accessor methods of the Persistent classes since the accessor methods pass their arguments to the value method and return the string value from the value method.

This class is part of the Persistent base package which is available from:

  http://www.bigsnow.org/persistent
  ftp://ftp.bigsnow.org/pub/persistent


DESCRIPTION

Before we get started describing the methods in detail, it should be noted that all error handling in this class is done with exceptions. So you should wrap an eval block around all of your code. Please see the Persistent documentation for more information on exception handling in Perl.


METHODS


Constructor -- Creates the VarChar Object

  eval {
    my $string = new Persistent::DataType::VarChar($value,
                                                   $max_length);
  };
  croak "Exception caught: $@" if $@;

Initializes a variable length character string object. This method throws Perl execeptions so use it with an eval block.

Parameters:

$value

Actual value of the string. This argument is optional and may be set to undef.

$max_length

Maximum length of the string value. This argument is optional and will be initialized to the length of the $value as a default or 1 if no $value argument is passed.


max_length -- Accesses the Maximum Length of the String

  eval {
    ### set the maximum length ###
    $string->max_length($new_max);

    ### get the maximum length ###
    $max_length = $string->max_length();
  };
  croak "Exception caught: $@" if $@;

Sets the maximum length of the string and/or returns it. This method throws Perl execeptions so use it with an eval block.

Parameters:

$max_length

Maximum length of the string value. The maximum length must be greater than zero, otherwise, an exception is thrown.


SEE ALSO

Persistent, Persistent::DataType::Char, Persistent::DataType::DateTime, Persistent::DataType::Number, Persistent::DataType::String


BUGS

This software is definitely a work in progress. So if you find any bugs please email them to me with a subject of 'Persistent Bug' at:

  winters@bigsnow.org

And you know, include the regular stuff, OS, Perl version, snippet of code, etc.


AUTHORS

  David Winters <winters@bigsnow.org>


COPYRIGHT

Copyright (c) 1998-2000 David Winters. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.