Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Need Perl6: Inline::Perl5 help

by duelafn (Parson)
on Mar 05, 2017 at 15:36 UTC ( [id://1183701]=note: print w/replies, xml ) Need Help??


in reply to Need Perl6: Inline::Perl5 help

This works:

#!/usr/bin/perl6 use Inline::Perl5; use Term::ANSIColor:from<Perl5> <color RED RESET>; my $Red = color("red"); my $Reset = color("reset"); say $Red ~ "--Red--" ~ $Reset; say RED ~ "--Red--" ~ RESET; say "{RED}--Red--{RESET}"; # And Laurent_R is right: my $Blue = Term::ANSIColor::color("blue"); say $Blue ~ "--Blue--" ~ $Reset;

Update: Another approach which works:

my $p5 = Inline::Perl5.new; $p5.use('Term::ANSIColor'); my $Green = $p5.call('Term::ANSIColor::GREEN'); say $Green ~ "--Green--" ~ $Reset;

However, this doesn't work (was trying to get around the AUTOLOAD):

Term::ANSIColor.YELLOW; # AUTOLOAD should generate YELLOW my $Yellow = Term::ANSIColor::YELLOW; # Hmm, nope :( at least not v +isible to Perl6 say $Yellow ~ "--Yellow--" ~ $Reset;

Good Day,
    Dean

Replies are listed 'Best First'.
Re^2: Need Perl6: Inline::Perl5 help
by Todd Chester (Scribe) on Mar 06, 2017 at 07:22 UTC
    Thank you all for the help and tips!

    Followup,

    This is my notes on Inline::Perl5. I hope this is useful to others.

    -T


    #!/usr/bin/perl6 # Inline::Perl5 test # Reference: https://github.com/niner/Inline-Perl5/commit/cc683dae98df +19db8cfbb551f7a87ef79bdc2a8b use Inline::Perl5; use Term::ANSIColor:from<Perl5>; # my $Red = Term::ANSIColor.RED; # my $Reset = Term::ANSIColor.RESET; my $Red = color('red'); my $Reset = color('reset'); print "High Level method:\n"; print $Red ~ "--Red--" ~ $Reset ~ "\n\n"; print "Low Level method:\n"; my $P5Color = Inline::Perl5.new; $P5Color.use( 'Term::ANSIColor' ); my $ResetColor = "RESET"; print ( $P5Color.call( 'Term::ANSIColor::GREEN' ) ~ "Red\n" ~ $P5Color.call( "Term::ANSIColor::$ResetColor" ) ~ "\n" ); my $p6str = "Perl 6 String"; my $perl5colors = Inline::Perl5.new(); $perl5colors.run(qq{ use Term::ANSIColor qw [ BLUE RESET ]; print "p5 term with color\n" . BLUE . "I am blue\n" . "$p6str" . RESET . "\n\n"; }); print "\'run\' method:\n"; my $perl5 = Inline::Perl5.new(); $perl5.run( ' print "Perl 5\' local time is " . localtime . "\n\n"; ' +); print "Test of return values\n"; my $RetStr = Inline::Perl5.new(); print $RetStr.run(qq{ return ( "P5 return string\n\n" ) });

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1183701]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-24 22:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found