Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Favorite MooseX Modules?

by Anonymous Monk
on Aug 07, 2009 at 19:34 UTC ( [id://786899]=note: print w/replies, xml ) Need Help??


in reply to Re: Favorite MooseX Modules?
in thread Favorite MooseX Modules?

I am trying to use MooseX::SimpleConfig and I cannot tell from the docs if this module actually sets your Moose attributes to the respective config values or not ... do you know?

When I set up a config file and and Moose class -- and then I instantiate and dump it -- all I see in the hash ref is a key for 'configfile' and the "attributes" inside my config file are not there.

Isn't the point of this module to set those values for me? So that I do not have to parse the config file nor explicitly set the attributes myself?

Replies are listed 'Best First'.
Re^3: Favorite MooseX Modules?
by phaylon (Curate) on Aug 07, 2009 at 20:55 UTC

    From what I can tell, there are two things you need to do:

    1. Create your own role that implements the get_config_from_file role, using a config loader of your choice (take a look at Config-Any).
    2. Use new_from_config instead of new. This method will initialize your object with the values returned by the get_config_from_file method.

    The synopsis has a more complex example of this.


    Ordinary morality is for ordinary people. -- Aleister Crowley
Re^3: Favorite MooseX Modules?
by stvn (Monsignor) on Aug 08, 2009 at 15:18 UTC

    Too add to what phaylon said ...

    I recommend looking closer at the SYNOPSIS for this module. It does not make &new magical (this is something we strongly discourage in Moose, &new should behave consistently across all classes), instead it provides an alternate constructor called &new_with_config, which expects the path of a config file, like so ...

    my $app = My::App->new_with_config(configfile => '/etc/my_app.yaml');
    This module also integrates with MooseX::Getopt such that the usual &new_with_options constructor that MooseX::Getopt supplies will accept and do the right thing for the -configfile option.

    MooseX::SimpleConfig is a Config::Any powered extension of MooseX::ConfigFromFile, which provides the basic building blocks. It is actually a rather simple setup, a quick read of the source of both these modules should tell you exactly what is going on.

    -stvn

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://786899]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-20 04:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found