From d6b91c794c382e3e764911a56af317443a3ef49f Mon Sep 17 00:00:00 2001 From: Carl Masak Date: Sun, 4 Apr 2010 00:42:07 +0200 Subject: [PATCH] [Yapsi] tried a subtype approach to Yapsi::IO Instead of a derivable class (which would have worked too), we try a duck-typing variant in which we only require the object stored in the attribute $!io to have a .say method. A bit lighter. --- lib/Yapsi.pm | 11 +++-------- yapsi | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/Yapsi.pm b/lib/Yapsi.pm index 4cdcf97..9832cb6 100644 --- a/lib/Yapsi.pm +++ b/lib/Yapsi.pm @@ -201,15 +201,10 @@ class Yapsi::Compiler { } } -class Yapsi::Runtime::IO { - method say($message) { - # RAKUDO: Can't use say in a method say [perl #74014] - print $message, "\n"; - } -} +subset Yapsi::IO where { .can('say') } class Yapsi::Runtime { - has Yapsi::Runtime::IO $!IO; + has Yapsi::IO $!io = $*OUT; method run(@sic) { my @r; @@ -252,7 +247,7 @@ class Yapsi::Runtime { %pad{~$0} = { :type, :value(+$1) }; } when /^ 'say $'(\d+) $/ { - $!IO.say: @r[+$0]; + $!io.say: @r[+$0]; } default { die "Couldn't handle instruction `$_`" } } diff --git a/yapsi b/yapsi index f1d99d7..e869e7d 100755 --- a/yapsi +++ b/yapsi @@ -16,7 +16,7 @@ else { try { my Yapsi::Compiler $compiler .= new; - my Yapsi::Runtime $runtime .= new(IO => Yapsi::Runtime::IO.new); + my Yapsi::Runtime $runtime .= new; my @sic = $compiler.compile($program); $runtime.run(@sic);