# New Ticket Created by  Salve J. Nilsen 
# Please include the string:  [perl #127492]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=127492 >


Please inspect the attached example test.

The following error appears when calling .perl on the Match object returned by 
a subclassed JSON::Tiny Grammar parser.

$ perl6 Match.perl-error.t 
1..3
    ok 1 - myparse accepts proper JSON text
    ok 2 - Parsing result is a Match object
This Seq has already been iterated, and its values consumed
(you might solve this by adding .cache on usages of the Seq, or
by assigning the Seq into an array)
  in block <unit> at Match.perl-error.t line 28

# vim: ft=perl6

use v6;
use JSON::Tiny::Grammar;
use JSON::Tiny::Actions;
use Test;

grammar A::B::Grammar is JSON::Tiny::Grammar { }
class A::B::Actions is JSON::Tiny::Actions { }

module A::B {
    proto myparse ($) is export { * };
    multi myparse (Str:D $json) {
        my $a = A::B::Actions.new;
        A::B::Grammar.parse( $json, :actions($a));
    }
}

import A::B; # we need the &myparse sub

plan 3;

subtest {
    my $result = myparse $=finish; # Read from POD
    ok $result, 'myparse accepts proper JSON text';
    isa-ok $result, 'Match', 'Parsing result is a Match object';

    ok $result.perl, 'We can call .perl on the Match object';

    #note "##### Match.gist is " ~ $result.gist; # This works
    #note "##### Match.perl is " ~ $result.perl; # THIS FAILS

}, "Parse JSON file and print stuff";

=finish

{
    "name"        : "JSON::Tiny",
    "version"     : "*",
    "description" : "A minimal JSON (de)serializer",
    "depends"     : [ ],
    "provides"    : {
        "JSON::Tiny"            : "lib/JSON/Tiny.pm",
        "JSON::Tiny::Actions"   : "lib/JSON/Tiny/Actions.pm",
        "JSON::Tiny::Grammar"   : "lib/JSON/Tiny/Grammar.pm"
    },
    "source-url"  : "git://github.com/moritz/json.git"
}

Reply via email to