Archive-TarGzip

 view release on metacpan or  search on metacpan

t/Archive/Data/Startup.pm  view on Meta::CPAN

# a new object with the override options, perserving
# the default object.
# 
sub override
{
     my $self = shift;
     return bless {},'Data::Startup' unless ref($self);

     #########
     # Create a duplicate object keeping the
     # the default object intact.
     # 
     my %options = %$self;
     $self = bless \%options,ref($self);
     return $self unless (@_);

     ##############
     # Do not want to gyrate around to any other
     # config in @ISA. Go directly to the one in this
     # program module.
     #
     $self->Data::Startup::config(@_);
     $self

}

=head1 NAME

Data::Startup - startup options class, override, config methods

=head1 SYNOPSIS

 use Data::Startup

 $startup_options = $class->Data::Startup::new( @option_list );
 $startup_options = $class->Data::Startup::new( \@option_list );
 $startup_options = $class->Data::Startup::new( \%option_list );

 $options = $startup_options->override( @option_list );
 $options = $startup_options->override( \@option_list );
 $options = $startup_options->override( \%option_list );

 @options_list = $options->config( );

 ($key, $old_value) = $options->config($key);
 ($key, $old_value) = $options->config($key => $new_value ); 
 ($key, $old_value) = $options->config($key => $new_value );

 @old_options_list = $options->config(@option_list);
 @old_options_list = $options->config(\@option_list);
 @old_options_list = $options->config(\%option_list);

 # Note: May use [@option_list] instead of \@option_list
 #       and {@option_list} instead of \%option_list

=head1 DESCRIPTION

Many times there is a group of subroutines that can be tailored by
different situations with a few, say global variables.
However, global variables pollute namespaces, become mangled
when the functions are multi-threaded and probably have many 
other faults that it is not worth the time discovering.

As well documented in literature, object oriented programming do not have
these faults.
This program module class of objects provide the objectized options
for a group of subroutines or encapsulated options by using
the methods directly as in an option object.

The C<Data::Startup> class provides a way to input options
in very liberal manner of either

=over 4

=item *

arrays, reference to an array, or reference to hash to a

=item *

reference to an array or reference to a hash

=item *

reference to a hash

=item *

referene to an array

=item *

many other combos

=back

without having to cut and paste specialize, tailored
code into each subroutine/method.

Some of the possiblities follows.

A subroutine may be utilize either as a subroutine or a method
of a object by processing the first argument of @_ by the 
following:

 sub my_suroutine
 {
     shift if UNIVERSAL::isa($_[0],__PACKAGE__);

     # ....

 }

The C<Data::Startup> class may be used to provide various 
options syntax for a dual methods/subroutines as follows:

 my $default_options = new( @default_options_list);

 # SYNTAX: my_subroutine1($arg1 .. $argn, @options)
 #         my_subroutine1($arg1 .. $argn, \@options)
 #         my_subroutine1($arg1 .. $argn, \%options)



( run in 1.045 second using v1.01-cache-2.11-cpan-39bf76dae61 )