Code Monkey home page Code Monkey logo

data-dpath's Issues

escapes inside filter

the different behaviour of single and double quotes inside of a filter is confusing to me and https://metacpan.org/pod/Data::DPath#Special-characters didnt entirely clear it up to us.

#!/usr/bin/env perl
use 5.018;
use warnings;
use Data::DPath 'dpath';

my $data = { foo => 'aaa[bbb/ccc]ddd' };

match( $data, q!/foo[value eq 'aaa\[bbb/ccc\]ddd']! );
match( $data, q!/foo[value eq 'aaa[bbb/ccc]ddd']! );
match( $data, q!/foo[value eq "aaa\\[bbb/ccc\\]ddd"]! );

sub match {
    my ($input_pl, $query_path) = @_;
    my $dpath = Data::DPath::Path->new( path => $query_path );
    my @result = $dpath->match($input_pl);
    say $query_path;
    say scalar @result ? 'match' : 'no match';
}
perl dpath.pl 
/foo[value eq 'aaa\[bbb/ccc\]ddd']
no match
/foo[value eq 'aaa[bbb/ccc]ddd']
no match
/foo[value eq "aaa\[bbb/ccc\]ddd"]
match

weird behaviour, newline in $path

depending on the input of a "value eq ..." query I get a string or a HASH ref.

code

#!/usr/bin/env perl
use 5.018;
use warnings;

use Data::DPath::Path;

sub _match {
    my ($path, $input) = @_;
    my $dpath  = Data::DPath::Path->new( path => $path );
    my @result = $dpath->match($input);

    use Data::Dumper;
    say "###\n$path";
    say Dumper(\@result);
}

my $input = { 'details' => 'foo bar baz' };

my $path1 = <<"HERE";
/details[ value eq 'foo bar baz' ]
HERE

my $path2 = <<"HERE";
/details[ value eq 'foo bar
baz' ]
HERE

_match($path1, $input);
_match($path2, $input);

output

###
/details[ value eq 'foo bar baz' ]

$VAR1 = [
          'foo bar baz'
        ];

###
/details[ value eq 'foo bar
baz' ]

$VAR1 = [
          {
            'details' => 'foo bar baz'
          }
        ];

Number found where operator expected at {path}/warnings.pm line {line}, near "caller 1

Data::DPath::Context isn't playing nice with Test::Exception.

Perl 5.26.0

perl -MTest::Exception -MData::DPath::Context -e '1'
Number found where operator expected at /Users/jonathantaylor/perl5/perlbrew/perls/perl-5.26.0/lib/5.26.0/warnings.pm line 353, near "caller 1"
        (Do you need to predeclare caller?)

Perl 5.16.3

perl -MTest::Exception -MData::DPath::Context -e '1'
Number found where operator expected at /Users/jonathantaylor/perl5/perlbrew/perls/perl-5.16.3/lib/5.16.3/warnings.pm line 444, near "caller 1"
        (Do you need to predeclare caller?)

Reversing the load order stops the warning from happening:

perl -MData::DPath::Context -MTest::Exception -e '1' # No warning

The behavior has something to do with how the Safe module is being used. Pull request forthcoming.

Name "main::INC" used only once: possible typo

Since 0.57, just using Data::DPath will warn here:

% perl -Ilib -w -e 'use Data::DPath'
Name "main::INC" used only once: possible typo at /usr/share/perl/5.26/Safe.pm line 372.

This can be reduced to just

% perl -w -MSafe -e 'BEGIN { $c = Safe->new; $c->reval("no warnings") }'
Name "main::INC" used only once: possible typo at /usr/share/perl/5.26/Safe.pm line 372.

so some more Safe polishing seems to be in order.

Seen on Debian unstable, Perl 5.26.1. Original report is at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=877093

Thanks for your work on Data-DPath.

Can't select specific array item (question)

#!/usr/bin/env perl
use 5.032;
use warnings;
use Data::DPath::Path;

my $query_path = '/*/*[2]/.[value eq "street"]/../*[3]/.[0]';
my $input_pl = [
  [ 1, "SUCCESS", 1000, "" ],
  [ 2, "ATTR", "street", "street1" ],
  [ 3, "ATTR", "street", "street2" ]
];

my $dpath  = Data::DPath::Path->new( path => $query_path );
my @result = $dpath->match($input_pl);

use Data::Dumper;
say Dumper(\@result);

this prints

$VAR1 = [
          'street1',
          'street2'
        ];

What path selects only one specific array item? For example, only street2.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.