Arrays in Config::General without resorting to copy/paste OR yaml

I'm trying to set a configuration file with Config::General and
apparently to set an Array, I need to the following example:
<example>
    lamp = linux
    lamp = apache
    lamp = mysql
    lamp = perl
</example>

When using keys that are long, it's simply a copy paste issue. Isn't
the a more comfortable way?

These don't work either:
  <lamp>
    linux, apache, mysql, perl
  </lamp>
--
<lamp>
    linux
    apache
    mysql
    perl
</lamp>

Anyone?
0
xsawyerx
10/29/2008 4:40:13 PM
perl.module-authors 1587 articles. 0 followers. Follow

4 Replies
436 Views

Similar Articles

[PageSpeed] 5

* On Wed, Oct 29 2008, Sawyer X wrote:
> I'm trying to set a configuration file with Config::General and
> apparently to set an Array, I need to the following example:
> <example>
>     lamp = linux
>     lamp = apache
>     lamp = mysql
>     lamp = perl
> </example>
>
> When using keys that are long, it's simply a copy paste issue. Isn't
> the a more comfortable way?
>
> These don't work either:
>   <lamp>
>     linux, apache, mysql, perl
>   </lamp>

What is stopping you from post-processing this into the data you want?
You are but a simple "split" away from having this syntax work.

Regards,
Jonathan Rockway

--
print just => another => perl => hacker => if $,=$"
0
jon
10/29/2008 6:15:23 PM
I'm using Moose with MooseX::SimpleConfig
I guess it'd be nicer if the configuration module (Config::Any) or
even MooseX::SimpleConfig role would do this instead of having to do

sub BUILD {
    my $self = shift;
    $self->method( [ split /,/, $self->method ] );
}


On Wed, Oct 29, 2008 at 8:15 PM, Jonathan Rockway <jon@jrock.us> wrote:
>
> * On Wed, Oct 29 2008, Sawyer X wrote:
> > I'm trying to set a configuration file with Config::General and
> > apparently to set an Array, I need to the following example:
> > <example>
> >     lamp = linux
> >     lamp = apache
> >     lamp = mysql
> >     lamp = perl
> > </example>
> >
> > When using keys that are long, it's simply a copy paste issue. Isn't
> > the a more comfortable way?
> >
> > These don't work either:
> >   <lamp>
> >     linux, apache, mysql, perl
> >   </lamp>
>
> What is stopping you from post-processing this into the data you want?
> You are but a simple "split" away from having this syntax work.
>
> Regards,
> Jonathan Rockway
>
> --
> print just => another => perl => hacker => if $,=$"
0
xsawyerx
10/29/2008 6:50:36 PM
* On Wed, Oct 29 2008, sawyer x wrote:
> I'm using Moose with MooseX::SimpleConfig
> I guess it'd be nicer if the configuration module (Config::Any) or
> even MooseX::SimpleConfig role would do this instead of having to do
>
> sub BUILD {
>     my $self = shift;
>     $self->method( [ split /,/, $self->method ] );
> }

In this case, I think you can write a custom Config::Any plugin:

  package Config::Any::Foo;
  sub extensions { 'foo' }
  sub load {
      my ($class, $filename, $args) = @_;
      ...
      if( whatever ) { split /, /, ... }
      return ...
  }

Then if you have a .foo file, this code will run to load it.  Totally
untested, but something like this should work.

BTW, I would just use YAML (or JSON) here.  Config::General is one of
the ugliest file formats I've ever seen, and it maps poorly to Perl.
YAML is nice looking and maps perfectly to Perl.

Regards,
Jonathan Rockway

--
print just => another => perl => hacker => if $,=$"
0
jon
10/30/2008 4:10:46 AM
I guess I can do that, but I think having a 1 liner BUILD subroutine
is simpler than writing an extension to Config::Any.

I'm afraid of starting a YAML vs. The World flamewar, but I don't like
YAML since it differs between white space and tab-created whitespace
and a few other small nuisances with it which effect the outcome and
hard to debug. It's not that readable as it claims. I might just have
to use it anyway though since it does provide a fair lot of
functionality.

Thanks for the ideas.

On Thu, Oct 30, 2008 at 6:10 AM, Jonathan Rockway <jon@jrock.us> wrote:
> * On Wed, Oct 29 2008, sawyer x wrote:
>> I'm using Moose with MooseX::SimpleConfig
>> I guess it'd be nicer if the configuration module (Config::Any) or
>> even MooseX::SimpleConfig role would do this instead of having to do
>>
>> sub BUILD {
>>     my $self = shift;
>>     $self->method( [ split /,/, $self->method ] );
>> }
>
> In this case, I think you can write a custom Config::Any plugin:
>
>  package Config::Any::Foo;
>  sub extensions { 'foo' }
>  sub load {
>      my ($class, $filename, $args) = @_;
>      ...
>      if( whatever ) { split /, /, ... }
>      return ...
>  }
>
> Then if you have a .foo file, this code will run to load it.  Totally
> untested, but something like this should work.
>
> BTW, I would just use YAML (or JSON) here.  Config::General is one of
> the ugliest file formats I've ever seen, and it maps poorly to Perl.
> YAML is nice looking and maps perfectly to Perl.
>
> Regards,
> Jonathan Rockway
>
> --
> print just => another => perl => hacker => if $,=$"
>
0
xsawyerx
10/30/2008 9:41:25 AM
Reply: