Created
December 5, 2015 18:54
-
-
Save Tux/afec03490da258d48671 to your computer and use it in GitHub Desktop.
Not OK (yet)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IO::String is IO::Handle { | |
has $.nl-in is rw; | |
has Str @!content; | |
multi method new (Str $str!) { | |
my \obj = self.bless; | |
obj.nl-in = $*IN.nl-in; | |
obj.print ($str); | |
obj; | |
} | |
method print (*@what) { | |
if (my Str $str = @what.join ("")) { | |
my Str @x = $str.split (self.nl-in); | |
@x[*] eq "" and @x.pop; | |
my $nl = self.nl-in[0]; | |
@!content.push: |@x.map ({ $_ ~ $nl }); | |
} | |
self; | |
} | |
method print-nl { | |
self.print ($.nl); | |
} | |
method get { | |
@!content or return Str; | |
shift @!content; | |
} | |
method Str { | |
@!content.join (""); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment