App-CSelUtils
view release on metacpan or search on metacpan
lib/App/CSelUtils.pm view on Meta::CPAN
my $node_res = $node;
for my $entry (@entries) {
my ($type, $name) = $entry =~ /\A(func|meth)::?(.+)\z/ or
return [400, "For action print_func_or_meth, ".
"specify func:FUNCNAME or meth:METHNAME"];
eval {
if ($type eq 'func') {
#use DD; say "func: $name(", DD::dump($node_res), ")";
$node_res = &{$name}($node_res);
} else {
#use DD; say "meth: $name on ", DD::dump($node_res);
$node_res = $node_res->$name;
}
};
if ($@) {
#warn $@;
$node_res = undef;
last;
}
}
push @{ $res->[2] }, $node_res;
}
} else {
return [400, "Unknown action '$action'"];
}
} # for $action
}
$res;
}
$SPEC{ddsel} = {
v => 1.1,
summary => 'Select Perl data structure elements using CSel (CSS-selector-like) syntax',
description => <<'_',
Note that this operates against Perl data structure, not Perl source code
elements (see <prog:ppisel> for that). File is Perl source code that defines
data structure, e.g.:
{
summary => 'This is a hash',
# this is an array inside a hash
array => [
1, 2, 3,
],
};
_
args => {
%foosel_args_common,
},
};
sub ddsel {
foosel(
@_,
code_read_tree => sub {
my $args = shift;
my $data;
if ($args->{file} eq '-') {
binmode STDIN, ":encoding(utf8)";
$data = eval join("", <>); ## no critic: BuiltinFunctions::ProhibitStringyEval
die if $@;
} else {
require File::Slurper;
$data = eval File::Slurper::read_text($args->{file}); ## no critic: BuiltinFunctions::ProhibitStringyEval
die if $@;
}
require Data::CSel::WrapStruct;
my $tree = Data::CSel::WrapStruct::wrap_struct($data);
$tree;
},
csel_opts => {class_prefixes=>['Data::CSel::WrapStruct']},
code_transform_node_actions => sub {
my $args = shift;
for my $action (@{ $args->{node_actions} }) {
if ($action eq 'print' || $action eq 'print_as_string') {
$action = 'print_func_or_meth:meth:value.func:Data::Dmp::dmp';
} elsif ($action eq 'dump') {
$action = 'dump:value';
}
}
},
);
}
1;
# ABSTRACT: Utilities related to Data::CSel
__END__
=pod
=encoding UTF-8
=head1 NAME
App::CSelUtils - Utilities related to Data::CSel
=head1 VERSION
This document describes version 0.089 of App::CSelUtils (from Perl distribution App-CSelUtils), released on 2022-10-17.
=head1 DESCRIPTION
This distribution contains the following utilities:
=over
=item * L<ddsel>
=item * L<parse-csel>
=back
=head1 FUNCTIONS
( run in 1.293 second using v1.01-cache-2.11-cpan-39bf76dae61 )