title: Perl Moose - What are the arguments when Loading valued from configuration files?
body: <p>In my previous question <a href="https://stackoverflow.com/questions/9777982/perl-moose-loading-values-from-configuration-file-etc">Moose - Loading values from conf files...</a> Jack Maney was kind enough to provide an example of how to do so using Moose.  </p>
  
  <p>In order to make the configuration object even more general I decided to use <a href="http://search.cpan.org/dist/Config-Auto/lib/Config/Auto.pm" rel="nofollow noreferrer">Config::Auto</a>.</p>
  
  <p>The problem is that I still am very green as to how Moose works.  For instance, Jack's example is:</p>
  
  <pre><code>package My::Module;
  use Moose;
  
  has 'config'=&gt;(isa=&gt;'HashRef[Str]',is=&gt;'rw',required=&gt;1);
  
  around BUILDARGS=&gt;sub
  {
    my $orig=shift;
    my $class=shift;
    my $args=shift; #other arguments passed in (if any).
  
    my %config_hash=();
    open(my $read,"&lt;","config_file") or confess $!;
    while(&lt;$read&gt;)
    {
      chomp;
      my @array=split /:/;
      $config_hash{$array[0]}=$array[1];
    }
    close($read);
  
    $args-&gt;{config}=\%config_hash;
  
    return $class-&gt;$orig($args);
  };
  
  no Moose;
  1;
  </code></pre>
  
  <p>I had modified it to this:</p>
  
  <pre><code>#!/usr/local/bin/perl
  package DART::Setup;
  
  use namespace::autoclean;
  use Moose;
  use Config::Auto;
  
  our $VERSION = '0.0.1';
  
  
  has 'EMPTY' =&gt; ( isa =&gt; 'Str', is =&gt; 'ro', default =&gt; q{} );
  has 'PPLTESTEXECUTIONID' =&gt; ( isa =&gt; 'Int', is =&gt; 'ro', default =&gt; 0 );
  has 'SARQTESTEXECUTIONID' =&gt; ( isa =&gt; 'Int', is =&gt; 'ro', default =&gt; 0 );
  has 'ISPROXY' =&gt; ( isa =&gt; 'Int', is =&gt; 'ro', default =&gt; 0 );
  has 'LOCALHOST' =&gt; ( isa =&gt; 'Str', is =&gt; 'ro', default =&gt; '127.0.0.1' );
  has 'config'=&gt;(isa=&gt;'HashRef[Str]',is=&gt;'rw',required=&gt;1);
  has 'SSO' =&gt; ( isa =&gt; 'Str', is =&gt; 'rw', default =&gt; q{} );
  has 'cookieFile' =&gt; ( isa =&gt; 'Str', is =&gt; 'rw', default =&gt; q{} );
  
  around BUILDARGS=&gt;sub
  {
    my $orig=shift;
    my $class=shift;
    my $args=shift;
  
    my $cfg = Config::Auto::parse($args);
    my %config_hash = %{$cfg};
  
    $args-&gt;{config}=\%config_hash;
  
    return $class-&gt;$orig($args);
  };
  
  
  return 1;
  </code></pre>
  
  <p>But to be honest I'm not sure what I'm doing here.  First off, how many arguments do I need to provide when I'm creating a new Setup object?  Do I just pass it the path to my configuration file, something like:</p>
  
  <pre><code>my $newConfig = DART::Setup-&gt;new('/home/y/conf/MyApp/MyApp.cfg');
  </code></pre>
  
  <p>Or do I need to provide arguments for $orig and $class?</p>
  
  <p>Finally, how do I now access my newly loaded configurations?  Can I do something like:</p>
  
  <pre><code>my %configHash = %{$newConfig-&gt;config()};
  
  foreach my $key (keys %configHash) {
  print "the key is, $key, and the value is: $configHash{$key}\n";
  }
  </code></pre>
  
  <p>Am I understanding this correctly?</p>