I would like to register the namespace for following module, which
has already been on CPAN in a completed state since August, and keep
the same name I already have. It is already in its own distribution.
Here is the DLSI:
Class::ParamParser - bdpO - Provides complex parameter list parsing.
This module is generic and would go in the general Class::* utilities
section, since it is intended for use in any kind of module/program.
I could not find any module in the list that provides the services
that mine does, so it should be unique.
My authorname is DUNCAND.
This class has received significant POD updates since the previous
release, mostly in its Synopsis section, but otherwise is unchanged.
I have printed the Name, Dependencies, Synopsis, and Description
below for your convenience. The Syntax is mostly unchanged from the
version on CPAN now.
If you have any questions then please contact me.
BTW, this module is the only one of mine that is currently listed in
the CPAN directory, which is surprising because it isn't in the
module list; normally the CPAN directory is a subset of the module
list (I think). Oh well. Now hopefully it will be in the module
list as well.
Thank you,
// Darren Duncan
------------------------
NAME
Class::ParamParser - Provides complex parameter list parsing.
DEPENDENCIES
Perl Version
5.004
Standard Modules
I<none>
Nonstandard Modules
I<none>
SYNOPSIS
use Class::ParamParser;
@ISA = qw( Class::ParamParser );
PARSING PARAMS INTO NAMED HASH
sub textfield {
my $self = shift( @_ );
my $rh_params = $self->params_to_hash( \@_, 0,
[ 'name', 'value', 'size', 'maxlength' ],
{ 'default' => 'value' } );
$rh_params->{'type'} = 'text';
return( $self->make_html_tag( 'input', $rh_params ) );
}
sub textarea {
my $self = shift( @_ );
my $rh_params = $self->params_to_hash( \@_, 0,
[ 'name', 'text', 'rows', 'cols' ], { 'default' => 'text',
'value' => 'text', 'columns' => 'cols' }, 'text' );
my $ra_text = delete( $rh_params->{'text'} );
return( $self->make_html_tag( 'textarea', $rh_params, $ra_text ) );
}
sub AUTOLOAD {
my $self = shift( @_ );
my $rh_params = $self->params_to_hash( \@_, 0, 'text', {}, 'text' );
my $ra_text = delete( $rh_params->{'text'} );
$AUTOLOAD =~ m/([^:]*)$/;
my $tag_name = $1;
return( $self->make_html_tag( $tag_name, $rh_params, $ra_text ) );
}
PARSING PARAMS INTO POSITIONAL ARRAY
sub property {
my $self = shift( @_ );
my ($key,$new_value) = $self->params_to_array(\@_,1,['key','value']);
if( defined( $new_value ) ) {
$self->{$key} = $new_value;
}
return( $self->{$key} );
}
sub make_html_tag {
my $self = shift( @_ );
my ($tag_name, $rh_params, $ra_text) =
$self->params_to_array( \@_, 1,
[ 'tag', 'params', 'text' ],
{ 'name' => 'tag', 'param' => 'params' } );
ref($rh_params) eq 'HASH' or $rh_params = {};
ref($ra_text) eq 'ARRAY' or $ra_text = [$ra_text];
return( join( '',
"<$tag_name",
(map { " $_=\"$rh_params->{$_}\"" } keys %{$rh_params}),
">",
@{$ra_text},
"</$tagname>",
) );
}
DESCRIPTION
This Perl 5 object class implements two methods which inherited
classes can use to tidy up parameter lists for their own methods and
functions. The two methods differ in that one returns a HASH ref
containing named parameters and the other returns an ARRAY ref
containing positional parameters.
Both methods can process the same kind of input parameter formats:
empty list
value
value1, value2, ...
name1 => value1, name2 => value2, ...
-name1 => value1, -name2 => value2, ...
{ -name1 => value1, name2 => value2, ... }
{ name1 => value1, -name2 => value2, ... }, valueR
Those examples included single or multiple positional parameters,
single or multiple named parameters, and a HASH ref containing named
parameters (with optional "remaining" value afterwards). That list
of input variations is not exhaustive. Named parameters can either
be prefixed with "-" or left natural.
We assume that the parameters are named when either they come as a
HASH ref or the first parameter begins with a "-". We assume that
they are positional if there is exactly one of them. Otherwise we
are in doubt and rely on an optional argument to the tidying method
that tells us which to guess by default.
We assume that any "value" may be an array ref (aka "multiple" values
under the same name) and hence we don't do anything special with
them, passing them as is.
If the source and destination are both positional, then they are identical.