in reply to Favorite MooseX Modules?

Actually I am surprised some of these aren't in Moose::Manual::MooseX already (although that is most likely because Dave wrote it and he doesn't (as far as I know) use these).

-stvn

Replies are listed 'Best First'.
Re^2: Favorite MooseX Modules?
by Boldra (Curate) on Aug 06, 2009 at 07:37 UTC
Re^2: Favorite MooseX Modules?
by metaperl (Curate) on Aug 05, 2009 at 19:54 UTC
Re^2: Favorite MooseX Modules?
by Anonymous Monk on Aug 07, 2009 at 19:34 UTC
    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?

      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

      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