Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

moosex::configfromfile(3pm) [debian man page]

MooseX::ConfigFromFile(3pm)				User Contributed Perl Documentation			       MooseX::ConfigFromFile(3pm)

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'; # optionally, default the configfile: sub configfile { '/tmp/foo.yaml' } # ... 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". Attributes specified directly as arguments to "new_with_config" supercede those in the configfile. MooseX::Getopt 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 Path::Class::File object which can be coerced from a regular pathname string. This is the file your attributes are loaded from. You can add a default configfile in the class using the role and it will be honored at the appropriate time: has +configfile ( default => '/etc/myapp.yaml' ); Note that you can alternately just provide a "configfile" method which returns the config file when called - this will be used in preference to the default of the attribute. 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 MooseX::Getopts'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()" which are sourced from the configfile. COPYRIGHT
Copyright (c) 2007 - 2009 the MooseX::ConfigFromFile "AUTHOR" and "CONTRIBUTORS" as listed below. AUTHOR
Brandon L. Black, <blblack@gmail.com> CONTRIBUTORS
Tomas Doran "<bobtfish@bobtfish.net>" (current maintainer). Karen Etheridge Chris Prather Zbigniew Lukasiak LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2011-12-17 MooseX::ConfigFromFile(3pm)

Check Out this Related Man Page

MooseX::Role::Parameterized::Extending(3)		User Contributed Perl Documentation		 MooseX::Role::Parameterized::Extending(3)

NAME
MooseX::Role::Parameterized::Extending - extending MooseX::Role::Parameterized roles DESCRIPTION
There are heaps of useful modules in the "MooseX" namespace that you can use to make your roles more powerful. However, they do not always work out of the box with MooseX::Role::Parameterized, but it's fairly straight-forward to achieve the functionality you desire. MooseX::Role::Parameterized was designed to be as extensible as the rest of Moose, and as such it is possible to apply custom traits to both the parameterizable role or the ordinary roles they generate. In this example, we will look at applying the fake trait "MooseX::MagicRole" to a parameterizable role. First we need to define a new metaclass for our parameterizable role. package MyApp::Meta::Role::Parameterizable; use Moose; extends 'MooseX::Role::Parameterized::Meta::Role::Parameterizable'; with 'MooseX::MagicRole'; This is a class (observe that it uses Moose, not Moose::Role) which extends the class which governs parameterizable roles. MooseX::Role::Parameterized::Meta::Role::Parameterizable is the metaclass that packages using MooseX::Role::Parameterized receive by default. Note that the class we are extending, MooseX::Role::Parameterized::Meta::Role::Parameterizable, is entirely distinct from the similarly- named class which governs the ordinary roles that parameterized roles generate. An instance of MooseX::Role::Parameterized::Meta::Role::Parameterized represents a role with its parameters already bound. Now we can take advantage of our new subclass by specifying that we want to use "MyApp::Meta::Role::Parameterizable" as our metaclass when importing MooseX::Role::Parameterized: package MyApp::Role; use MooseX::Role::Parameterized -metaclass => 'MyApp::Meta::Role::Parameterizable'; role { ... } And there you go! "MyApp::Role" now has the "MooseX::MagicRole" trait applied. perl v5.16.2 2010-12-24 MooseX::Role::Parameterized::Extending(3)
Man Page