28 |
|
|
29 |
$templates{values_section} = { |
$templates{values_section} = { |
30 |
rules => [ q( |
rules => [ q( |
31 |
if ($in =~ s/^\s*(.*?)\s*=\s*(.*)\s*$//) { |
if ($in =~ s/^\s*(\S+)\s*=\s*("([^"]*)"|'([^']*)'|[^'"\s]+)\s*$//) { |
32 |
|
print " YES $1 - $2 - $3\n"; |
33 |
|
#use Data::Dumper; |
34 |
|
#print Dumper($out->{current_sections}) . "\n"; |
35 |
$atom->{type} = 'KEY_VALUE'; |
$atom->{type} = 'KEY_VALUE'; |
36 |
$atom->{key} = $1; |
$atom->{key} = $1; |
37 |
$atom->{value} = $2; |
$atom->{value} = defined $3 ? $3 : $2; |
38 |
$out->{current_section} and $atom->{sections} = [ $out->{current_section} ]; |
$atom->{sections} = [ @{$out->{current_sections}} ]; |
39 |
$matched = 1; |
$matched = 1; |
40 |
} |
} |
41 |
), |
), |
43 |
if ($in =~ s/^\s*\[([^\]]+)\]\s*$//) { |
if ($in =~ s/^\s*\[([^\]]+)\]\s*$//) { |
44 |
$atom->{type} = 'SECTION'; |
$atom->{type} = 'SECTION'; |
45 |
$atom->{section_name} = $1; |
$atom->{section_name} = $1; |
46 |
$out->{current_section} = { name => $1 }; |
$atom->{sections} = [ ]; |
47 |
|
$out->{current_sections} = [ { name => $1 } ]; |
48 |
$matched = 1; |
$matched = 1; |
49 |
} |
} |
50 |
), |
), |
63 |
$out->{current_indentation} = 1; |
$out->{current_indentation} = 1; |
64 |
), |
), |
65 |
}, |
}, |
66 |
|
|
67 |
edit_atom => q( |
edit_atom => q( |
68 |
if ($index == -1) { |
if ($index == -1) { |
69 |
my $i = 0; |
my $i = 0; |
70 |
foreach (@{$out->{atoms}}) { |
foreach my $atom (@{$out->{atoms}}) { |
71 |
$_->{key} eq $args{key} and $index = $i; #we don't exit the loop, to have the last atom if multiples ones match |
#$atom->{$_} ne $args->{$_} and next foreach (keys(%args)); |
72 |
$i++; |
#we don't exit the loop, to have the last atom if multiples ones match |
73 |
|
$atom->{key} eq $args{key} && |
74 |
|
(exists($args{sections}) ? $atom->{sections}[0]{name} eq $args{sections}[0]{name} : 1) |
75 |
|
and $index = $i; |
76 |
|
$i++; |
77 |
} |
} |
78 |
$index == -1 and return -2; |
$index == -1 and return -2; |
79 |
} |
} |
80 |
@{@{$out->{atoms}}[$index]}{keys(%args)} = values(%args) |
@{@{$out->{atoms}}[$index]}{keys(%args)} = values(%args); |
81 |
|
return $index; |
82 |
), |
), |
83 |
|
find_atom_pos => q( |
84 |
|
$first_atom ||= 0; |
85 |
|
$last_atom ||= @{$out->{atoms}}-1; |
86 |
|
my @res; |
87 |
|
foreach my $pos ($first_atom..$last_atom) { |
88 |
|
my $atom = $out->{atoms}->[$pos]; |
89 |
|
my $flag = 1; |
90 |
|
foreach (keys(%args)) { |
91 |
|
if ($_ eq 'sections') { |
92 |
|
$atom->{sections}[0]{name} eq $args{sections}->[0]{name} or $flag = 0; |
93 |
|
} else { |
94 |
|
$atom->{$_} eq $args{$_} or $flag = 0; |
95 |
|
} |
96 |
|
} |
97 |
|
$flag and push(@res, $pos); |
98 |
|
} |
99 |
|
wantarray ? @res : $res[-1]; |
100 |
|
), |
101 |
}; |
}; |
102 |
|
|
103 |
1 |
1 |