Debian Codegraph @

t/scan/keyword_declare.t

raw
1 use strict;
2 use warnings;
3 use FindBin;
4 use lib "$FindBin::Bin/../../";
5 use Test::More;
6 use t::scan::Util;
7
8 test(<<'TEST'); # DCONWAY/Keyword-Declare-0.001009/dlib/Multilingual/Code.pm
9 use Keyword::Declare;
10
11 sub import {
12 keytype Blocklike is / (?= \{ ) (?&PPR_quotelike_body) /;
13
14 our $next_anon = 'ANON00000001';
15 keyword ANSI_C (Blocklike $block) {
16 my ($c_params, $perl_args) = (q{}, q{});
17 my $anon_sub = $Multilingual::Code::next_anon++;
18 my %seen;
19 $block =~ s{\$(\w+)}{ if (!$seen{$1}++) { $c_params .= "char* $1,"; $perl_args .= "\$$1,"; } $1 }gexms;
20 $c_params =~ s{,$}{};
21 return qq[
22 use Inline C => q{void $anon_sub ($c_params) $block};
23 $anon_sub($perl_args);
24 ];
25 }
26 keyword PYTHON (Blocklike $block) {
27 use List::Util 'minstr';
28 my ($py_params, $perl_args) = (q{}, q{});
29 my $anon_sub = $Multilingual::Code::next_anon++;
30 my %seen;
31 $block =~ s{\A \{ | \} \Z}{}gx;
32 my $prefix = minstr( grep {defined} $block =~ m{^(\h+)}gcxms );
33 $block =~ s{^$prefix}{}gm;
34 $block =~ s{(?<sigil> [\$\@] ) (?<name> \w+ ) }
35 { my %var = %+;
36 if (!$seen{$var{name}}++) {
37 $py_params .= "$var{name},";
38 $perl_args .= '\\' if $var{sigil} eq '@';
39 $perl_args .= "$var{sigil}$var{name},";
40 }
41 $var{name}
42 }gexms;
43 $py_params =~ s{,$}{};
44 my ($defs, $execs) = (q{}, q{});
45 for my $construct (split m{^(?=\S)}xm, $block) {
46 if ($construct =~ /\A\s*def\b/) { $defs .= $construct; }
47 else { $execs .= $construct; }
48 }
49 $execs =~ s{^}{ }gm;
50 return ($defs =~ /\S/ ? qq[ use Inline Python => q{$defs}; ] : q{})
51 . ($execs =~ /\S/ ? qq[ use Inline Python => q{def $anon_sub($py_params):\n$execs}; $anon_sub($perl_args); ] : q{});
52 }
53
54 keyword LATIN (Blocklike $code) {
55 use Lingua::Romana::Perligata ();
56 local $_ = substr($code, 1, -2);
57 Lingua::Romana::Perligata::filter();
58 return "{no strict; no warnings; $_}";
59 }
60 }
61 TEST
62
63 done_testing;