Advertisement
Xliff

Trying to call P5 code...

Apr 8th, 2016
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 1.22 KB | None | 0 0
  1. #/usr/bin/perl6
  2.  
  3. use Inline::Perl5;
  4. use Mojo::DOM:from<Perl5>;
  5.  
  6. my $p5 = Inline::Perl5.new;
  7.  
  8. $p5.run(q'
  9.     sub mojo_find {
  10.         my ($m, $t) = @_;
  11.  
  12.         print $m;
  13.  
  14.         return $m->children($t);
  15.     }
  16. ');
  17.  
  18. for dir(test => /:i '.' html $/).sort -> $file {
  19.     my $fh = $file.open;
  20.     my $contents = $fh.slurp-rest;
  21.  
  22.     say "=== $file ===";
  23.     #$contents ~~ s/.+? ('<' p.+? '>')/$0/;
  24.  
  25.     my $m = Mojo::DOM.new($contents);
  26.     say $m;
  27.  
  28.     my $count = 0;
  29.     #my @tags = $contents ~~  m:g/ :r '<' (<-[\s]>+(.+?)?) '>' (.+) '</' $0 '>'/;
  30.     my @tags = $p5.call('mojo_find', $m, 'p');
  31.     for @tags -> $t {
  32.         say $t;
  33.         last if $count++ > 10;
  34.     }
  35.  
  36.     last;
  37.  
  38. }
  39.  
  40. ====
  41. Output
  42. ====
  43.  
  44. $ perl6 reBase.pl
  45. === index_split_001.html ===
  46. Inline::Perl5::Perl5Object.new(ptr => NativeCall::Types::Pointer.new(216816896), perl5 => Inline::Perl5.new)
  47. Can't call method "tree" on an undefined value at /usr/local/share/perl/5.22.1/Mojo/DOM/HTML.pm line 166.
  48.  
  49.  in method call at /home/cbwood/.rakudobrew/moar-nom/install/share/perl6/site/sources/2DDC3CA4D43E8307229B622394E5256F089707DD (Inline::Perl5) line 472
  50.  in block <unit> at reBase.pl line 30
  51.  
  52. Attempt to free nonexistent shared string 'render', Perl interpreter: 0xb53fa58 during global destruction.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement