Skip Menu |

This queue is for tickets about the YAML-AppConfig CPAN distribution.

Report information
The Basics
Id: 60661
Status: open
Priority: 0/
Queue: YAML-AppConfig

People
Owner: Nobody in particular
Requestors: mohy [...] pair.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Variables
Date: Mon, 23 Aug 2010 19:25:17 -0400 (EDT)
To: bug-YAML-AppConfig [...] rt.cpan.org
From: mohy <mohy [...] pair.com>
Hello, I would like to thank you for your module. It is simple yet brilliant. The ability to add variables in the yaml file and auto concatenate make it very useful. I believe AppConfig can be much more that just a configuration application. Having variables makes it easy to eliminate duplications. Something I really like as a programmer. I have taken the liberty of trying to extend your module's capabilities. Allowing the variables to traverse threw hashes and arrays can prove to be useful. I was able to implement it by accessing the hash directly. My code might be crude. There might be a better way of doing it. I don't see it changing any of the current functionality but I might have missed something or may be there is a more reliable way of implementing it. Of course I leave all the final decisions of what to add to you. Here is a diff of what I currently have. I hope it helps. Let me know if you need anything. <pre> 181a182 Show quoted text
> my $exp = qr/(?<!\\)(\$(?:(?:{\w+}|\w+|\[\d+\])+(?:->)?)+)/;
183c184 < split /((?<!\\)\$(?:{\w+}|\w+))/, $value; --- Show quoted text
> split $exp, $value;
185,187c186,197 < if ( $part =~ /^(?<!\\)\$(?:{(\w+)}|(\w+))$/) { < my $name = $1 || $2; < $part = $self->_get($name) if $self->_scope_has($name); --- Show quoted text
> if ( $part =~ /^$exp$/ ) { > my @params = grep length, split /\$|{|}|\[|\]|->/, $part; > my $data = dclone $self->{config}; > foreach my $param (@params){ > last unless($data); > if ( ref $data eq 'HASH' ){ > $data = $data->{$param}; > } elsif ( ref $data eq 'ARRAY' and $param =~ /^\d+$/) { > $data = @$data[$param]; > } > } > $part = $data if($data);
Test Ex: val1 : test1: array: - 1 - 2 - 3 : - val2 - val3 test2 : >- $val1->{test1}{array}[1] is the value for $val1->{test1}{array}[2]{3}[0] Result: $app->get_test2; # 2 is the value for val2 </pre> -Mohy