App-Framework

 view release on metacpan or  search on metacpan

lib/App/Framework/Feature/Args.pm  view on Meta::CPAN


=over 4

=item B<user_args> - list of argument definitions

Created by the object. Once all of the arguments have been created, this field contains an ARRAY ref to the list
of all of the specified option specifications (see method L</append_args>).

=item B<arg_names> - list of argument names

Created by the object. Once all of the arguments have been created, this field contains an ARRAY ref to the list
of all of the argument names.

=item B<argv> - list of command line arguments

Reference to @ARGV array.

=back

=cut

my %FIELDS = (
	## User specified
	'user_args'		=> [],		# User-specified args
	'argv'		=> [],		# ref to @ARGV
	'arg_names'	=> [],		# List of arg names

	## Created
	'_arg_list'			=> [],	# Final ARRAY ref of args - EXCLUDING any opened files
	'_args'				=> {},	# Final args HASH - key = arg name; value = arg value
	'_arg_names_hash'	=> {},	# List of HASHes, each hash contains details of an arg
	'_fh_list'			=> [],	# List of any opened file handles
) ;

#============================================================================================

=head2 CONSTRUCTOR

=over 4

=cut

#============================================================================================


=item B< new([%args]) >

Create a new Args.

The %args are specified as they would be in the B<set> method (see L</Fields>).

=cut

sub new
{
	my ($obj, %args) = @_ ;

	my $class = ref($obj) || $obj ;

	# Create object
	my $this = $class->SUPER::new(%args,
	) ;


my $args = $this->feature_args() ;
$this->_dbg_prt(["NEW: feature args=", $args]) ;
$this->_dbg_prt(["OBJ=", $this]) ;
	
	return($this) ;
}



#============================================================================================

=back

=head2 CLASS METHODS

=over 4

=cut

#============================================================================================


#-----------------------------------------------------------------------------

=item B< init_class([%args]) >

Initialises the Args object class variables.

=cut

sub init_class
{
	my $class = shift ;
	my (%args) = @_ ;

	# Add extra fields
	$class->add_fields(\%FIELDS, \%args) ;

	# init class
	$class->SUPER::init_class(%args) ;

}

#============================================================================================

=back

=head2 OBJECT METHODS

=over 4

=cut

#============================================================================================

#----------------------------------------------------------------------------

=item B< args([$name]) >

When called with no arguments, returns the full arguments list (same as call to method L</arg_list>).

When a name (or list of names) is specified: if the named arguments hash is available, returns the 
argument values as a list; otherwise just returns the complete args list.

=cut

sub args
{
	my $this = shift ;
	my (@names) = @_ ;
	
	my $args_href = $this->_args() ;
	my @args = $this->arg_list ;

	if (keys %$args_href)
	{
		# do named args
		if (@names)
		{
			@args = () ;
			foreach my $name (@names)
			{
				push @args, $args_href->{$name} if exists($args_href->{$name}) ;
			}			
		}
	}	
	
	return @args ;
}

#----------------------------------------------------------------------------

=item B< Args([$name]) >

Alias to L</args>

=cut

*Args = \&args ;



( run in 1.349 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )