App-Framework

 view release on metacpan or  search on metacpan

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


=head2 FIELDS

The following fields should be defined either in the call to 'new()', as part of a 'set()' call, or called by their accessor method
(which is the same name as the field):


=over 4

=item B<user_options> - list of options

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

=item B<option_names> - list of options names

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

=back

=cut

my %FIELDS = (
	'user_options'	=> [],		# User-specified options
	'option_names'	=> [],		# List of option names

	'_options'				=> {},	# Final options HASH - key = option name; value = option value
	'_option_fields_hash'	=> {},	# List of HASHes, each hash contains details of an option
	'_get_options'			=> [],	# Options converted into list for GetOpts
	'_options_list'			=> [],	# Processed list of options (with duplicates removed)
) ;


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

=head2 CONSTRUCTOR

=over 4

=cut

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


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

Create a new Options.

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

=cut

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

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

	# Create object
	my $this = $class->SUPER::new(%args,
		'priority' 		=> $App::Framework::Base::PRIORITY_SYSTEM + 10,		# needs to be before data
#		'registered'	=> [qw/getopts_entry/],
	) ;

	
	return($this) ;
}



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

=back

=head2 CLASS METHODS

=over 4

=cut

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


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

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

Initialises the Options 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< options() >

Feature accessor method (aliases on the app object as B<options>)

Returns the hash of options/values

=cut

sub options
{
	my $this = shift ;

$this->_dbg_prt( ["Options()\n"] ) ;

	my $options_href = $this->_options() ;
	return %$options_href ;
}

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

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

Alias to L</options>

=cut

*Options = \&options ;

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

=item B<option($option_name)>

Returns the value of the named option

=cut

sub option
{
	my $this = shift ;
	my ($option_name) = @_ ;

	my $options_href = $this->_options() ;



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