Help-Site Computer Manuals
Software
Hardware
Programming
Networking
  Algorithms & Data Structures   Programming Languages   Revision Control
  Protocols
  Cameras   Computers   Displays   Keyboards & Mice   Motherboards   Networking   Printers & Scanners   Storage
  Windows   Linux & Unix   Mac

MooseX::ConfigFromFile
An abstract Moose role for setting attributes from a configfile

MooseX::ConfigFromFile - An abstract Moose role for setting attributes from a configfile



NAME

MooseX::ConfigFromFile - An abstract Moose role for setting attributes from a configfile


SYNOPSIS


  ########

  ## A real role based on this abstract role:

  ########

  package MooseX::SomeSpecificConfigRole;

  use Moose::Role;

  

  with 'MooseX::ConfigFromFile';

  

  use Some::ConfigFile::Loader ();

  sub get_config_from_file {

    my ($class, $file) = @_;

    my $options_hashref = Some::ConfigFile::Loader->load($file);

    return $options_hashref;

  }

  ########

  ## A class that uses it:

  ########

  package Foo;

  use Moose;

  with 'MooseX::SomeSpecificConfigRole';

  # ... insert your stuff here ...

  ########

  ## A script that uses the class with a configfile

  ########

  my $obj = Foo->new_with_config(configfile => '/etc/foo.yaml', other_opt => 'foo');


DESCRIPTION

This is an abstract role which provides an alternate constructor for creating objects using parameters passed in from a configuration file. The actual implementation of reading the configuration file is left to concrete subroles.

It declares an attribute configfile and a class method new_with_config, and requires that concrete roles derived from it implement the class method get_config_from_file.

the MooseX::Getopt manpage knows about this abstract role, and will use it if available to load attributes from the file specified by the commandline flag --configfile during its normal new_with_options.


Attributes

configfile

This is a the Path::Class::File manpage object which can be coerced from a regular pathname string. This is the file your attributes are loaded from.


Class Methods

new_with_config

This is an alternate constructor, which knows to look for the configfile option in its arguments and use that to set attributes. It is much like the MooseX::Getopts manpage's new_with_options. Example:


  my $foo = SomeClass->new_with_config(configfile => '/etc/foo.yaml');

Explicit arguments will overide anything set by the configfile.

get_config_from_file

This class method is not implemented in this role, but it is required of all subroles. Its two arguments are the classname and the configfile, and it is expected to return a hashref of arguments to pass to new().

meta

The Moose meta stuff, included here because otherwise pod tests fail sometimes


BUGS


AUTHOR

Brandon L. Black, <blblack@gmail.com>


LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Programminig
Wy
Wy
yW
Wy
Programming
Wy
Wy
Wy
Wy