Mildew
view release on metacpan or search on metacpan
WIP/lib/Mildew/AST/Helpers.pm view on Meta::CPAN
package Mildew::AST::Helpers;
BEGIN {
$Mildew::AST::Helpers::VERSION = '0.05';
}
use Exporter 'import';
our @EXPORT = qw(string reg integer call FETCH lookup capturize let fcall name_components empty_sig routine code move_CONTROL XXX trailing_return varname lookupf curlies named_and_positional dump lookup_package YYY wrap_in_block);
use Carp 'confess';
use Term::ANSIColor qw(:constants);
use PadWalker qw(peek_my);
use YAML::XS qw(Dump);
use utf8;
use strict;
sub YYY {
use YAML::XS;
# Mildew::prune($_[0]);
die Dump($_[0]);
}
sub string($) {
Mildew::AST::StringConstant->new(value=>$_[0]);
}
sub reg($) {
Mildew::AST::Reg->new(name=>$_[0]);
}
sub integer($) {
Mildew::AST::IntegerConstant->new(value=>$_[0]);
}
sub call {
Mildew::AST::Call->new(identifier=>string($_[0]),capture=>Mildew::AST::Capture->new(invocant => $_[1],positional => $_[2]//[],named => $_[3]//[]));
}
sub FETCH {
my $arg = shift;
call FETCH => $arg
}
sub lookup {
my $thing = shift;
call lookup => reg '$scope',[string $thing];
}
sub lookupf {
FETCH(lookup(@_));
}
sub curlies {
my $thing = shift;
call 'postcircumfix:{ }' => reg '$scope',[string $thing];
}
sub fcall {
my $func = shift;
unless (ref $func) {
$func = FETCH(lookup($func));
}
call 'postcircumfix:( )' => $func, [capturize(@_)];
}
sub capturize {
my ($pos,$named) = @_;
Mildew::AST::Call->new(
identifier => string "new",
capture => Mildew::AST::Capture->new(
invocant => FETCH(lookup("capture")),
positional => $pos // [],
named => $named // []
)
( run in 0.644 second using v1.01-cache-2.11-cpan-437f7b0c052 )