Config-IOD
view release on metacpan or search on metacpan
lib/Config/IOD/Document.pm view on Meta::CPAN
$merge = @$args ? $args->[0] : undef;
} # ignore the other directives
} elsif ($type eq 'S') {
$num_seen_section_lines++;
# merge previous section
$_merge->() if defined($merge) && $num_seen_section_lines > 1;
$cur_section = $line->[COL_S_SECTION];
$parser->{_cur_section} = $cur_section if $parser->{enable_expr}; #TMP HACK
$res->{$cur_section} //= {};
} elsif ($type eq 'K') {
# the common case is that value are not decoded or
# quoted/bracketed/braced, so we avoid calling _parse_raw_value here
# to avoid overhead
my $key = $line->[COL_K_KEY];
my $val = $line->[COL_K_VALUE_RAW];
if ($val =~ /\A["!\\[\{]/) {
my ($err, $parse_res, $decoded_val) =
$parser->_parse_raw_value($val);
die "IOD document:$linum: Invalid value: $err" if $err;
$val = $decoded_val;
} else {
$val =~ s/\s*[#;].*//; # strip comment
}
if (exists $res->{$cur_section}{$key}) {
if (!$parser->{allow_duplicate_key}) {
die "IOD document:$linum: Duplicate key: $key ".
"(section $cur_section)";
} elsif ($arrayified->{$cur_section}{$key}++) {
push @{ $res->{$cur_section}{$key} }, $val;
lib/Config/IOD/Document.pm view on Meta::CPAN
=item * all => bool
If set to 1, then will delete all occurrences. By default only delete the first
occurrence.
=item * cond => code
Will only delete key if C<cond> returns true. C<cond> will be called with C<<
($self, %args) >> where the hash will contain these keys: C<linum> (int, line
number), C<parsed> (array, parsed line), C<key> (string, key name), C<value>
(NOT YET IMPLEMENTED), C<raw_value> (str, raw/undecoded value).
=back
=head2 $doc->delete_section([\%opts, ]$section) => $num_deleted
Delete section named C<$section>.
Options:
=over
lib/Config/IOD/Document.pm view on Meta::CPAN
Will only delete section if C<cond> returns true. C<cond> will be called with
C<< ($self, %args) >> where the hash will contain these keys: C<linum_start>
(int, starting line number), C<linum_end> (int, ending line number).
=back
=head2 $doc->dump([ \%opts ]) => hoh
Return a hoh (hash of section names and hashes, where each of the second-level
hash is of keys and values), Values will be decoded and merging will be done,
but includes are not processed (even though C<include> directive is active).
Options:
=over
=item * linum_start => int
Only dump beginning from this line number.
lib/Config/IOD/Document.pm view on Meta::CPAN
Only dump until this line number.
=back
=head2 $doc->each_key([ \%opts , ] $code) => LIST
Execute C<$code> for each key found in document, in order of occurrence.
C<$code> will be called with arguments C<< ($self, %args) >> where C<%args> will
contain these keys: C<section> (str, current section name), C<key> (str, key
name), C<value> (any, value, NOT YET IMPLEMENTED/AVAILABLE), C<raw_value> (str,
raw/undecoded value), C<linum> (int, line number, 1-based), C<parsed> (array,
parsed line).
Options:
=over
=item * linum_start => int
Only dump beginning from this line number.
lib/Config/IOD/Document.pm view on Meta::CPAN
without any blank line, e.g.:
;!lint_prereqs assume-used "undetected, used via Riap"
App::MyApp=0
If found, will return an arrayref containing directive name and arguments.
Otherwise, will return undef.
=head2 $doc->get_value($section, $key) => $value
Get value. Values are decoded and section merging is respected, but includes are
not processed.
Internally, will do a C<dump()> and cache the result so subsequent
C<get_value()> will avoid re-parsing the whole document. (The cache will
automatically be discarded is one of document-modifying methods like
C<delete_section()> is called.)
=head2 $doc->insert_key([\%opts, ]$section, $key, $value) => int
Insert a key named C<$name> with value C<$value> under C<$section>. Return line
( run in 0.423 second using v1.01-cache-2.11-cpan-26ccb49234f )