NAME
SPOPS::Tie::StrictField - Enable field checking for SPOPS objects
SYNOPSIS
use SPOPS::Tie::StrictField;
my ( %data );
my @fields = qw( first_name last_name login birth_date );
tie %data, 'SPOPS::Tie::StrictField', $class, \@fields;
# Trigger warnings by trying to store a misspelled
# or unknown property
# 'login' is the correct field
$data{login_name} = 'cb';
# not in @fields list
$data{middle_name} = 'Amadeus';
DESCRIPTION
This class subclasses SPOPS::Tie, adding field-checking functionality. When you tie the hash, you also pass it a hashref of extra information, one key of which should be 'field'. The 'field' parameter specifies what keys may be used to access data in the hash. This is to ensure that when you set or retrieve a property it is properly spelled.
If you do not specify the 'field' parameter properly, you will get normal SPOPS::Tie functionality, which might throw a monkey wrench into your application since you and any users will expect the system to not silently accept misspelled object keys.
For instance:
my ( %data );
my $class = 'SPOPS::User';
tie %data, 'SPOPS::Tie::StrictField', $class, [ qw/ first_name last_name login / ];
$data{firstname} = 'Chucky';
would result in a message to STDERR, something like:
Error setting value for field (firstname): it is not a valid field
at my_tie.pl line 9
since you have misspelled the property, which should be 'first_name'.
SEE ALSO
COPYRIGHT
Copyright (c) 2001-2004 intes.net, inc.. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHORS
Chris Winters <chris@cwinters.com>