CGI-MxScreen
view release on metacpan or search on metacpan
MxScreen/Form/Field.pm view on Meta::CPAN
# $EndLog$
#
use strict;
package CGI::MxScreen::Form::Field;
use CGI;
use Carp::Datum;
use Log::Agent;
use Getargs::Long qw(ignorecase);
# index of the array
BEGIN {
sub NAME () {0}
sub MANDATORY () {1}
sub VERIFY_ARG () {2} # VERIFY conflict with Carp::Datum's
sub STORAGE () {3}
sub PATCH () {4}
sub NOSTORAGE () {5}
sub CGI_ARGS () {6}
sub VALUE () {7}
sub ERROR () {8}
}
#
# ->make
#
# Arguments: (that are considered, others values are kept aside)
# -name => string
# -mandatory => boolean
# -verify => 'routine' or ['routine', args ...]
# -patch => 'routine' or ['routine', args ...]
# -storage => 'symbol' or [objref, 'routine', arg] or [ref, 'symbol']
# -nostorage => boolean
#
sub make {
DFEATURE my $f_;
my $self = bless [], shift;
my ($name, $default) = cxgetargs(@_, { -strict => 0, -extra => 0 },
-name => 's',
-default => [],
);
# Initial value at creation time
my $param = CGI::param($name);
$self->[VALUE] = defined($param) ? $param : $default;
$self->[ERROR] = '';
$self->update(@_);
return DVAL $self;
}
#
# ->update
#
#
sub update {
DFEATURE my $f_;
my $self = shift;
($self->[NAME],
$self->[MANDATORY],
$self->[VERIFY_ARG],
$self->[STORAGE],
$self->[PATCH],
$self->[NOSTORAGE],
@{$self->[CGI_ARGS]}) =
cxgetargs(@_, {-strict => 0},
-name => 's',
-mandatory => ['i'],
-verify => [],
-storage => [],
-patch => [],
-nostorage => ['i']
);
unshift @{$self->[CGI_ARGS]}, ('-name', $self->name);
return DVOID;
}
# Temporary method
#
# To Be Removed
# when storable would be able to select what is stored with
# Storable::Hook
sub cleanup {
DFEATURE my $f_;
my $self = shift;
$#{$self} = NOSTORAGE;
return DVOID;
}
#########################################################################
# Class Feature: usable from the external world #
#########################################################################
sub name { $_[0]->[NAME] }
sub mandatory { $_[0]->[MANDATORY] }
sub verify { $_[0]->[VERIFY_ARG] }
sub storage { $_[0]->[STORAGE] }
sub patch { $_[0]->[PATCH] }
sub nostorage { $_[0]->[NOSTORAGE] }
sub value { $_[0]->[VALUE] }
sub error { $_[0]->[ERROR] }
sub set_value { $_[0]->[VALUE] = $_[1] }
sub set_error { $_[0]->[ERROR] = $_[1] }
#
# ->properties
#
# return the full list of arg that were given at creation time. The
# result can be used to supply the CGI functions.
( run in 1.012 second using v1.01-cache-2.11-cpan-f56aa216473 )