Skip to content

Commit

Permalink
Start to move some methods in IO over to the Perl 6 setting, improvin…
Browse files Browse the repository at this point in the history
…g error handling to be more in line with S32 along the way.
  • Loading branch information
jnthn committed Mar 20, 2009
1 parent 83e060f commit 7b9f811
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 53 deletions.
1 change: 1 addition & 0 deletions build/Makefile.in
Expand Up @@ -114,6 +114,7 @@ SETTING = \
src/setting/Array.pm \
src/setting/Bool.pm \
src/setting/Hash.pm \
src/setting/IO.pm \
src/setting/List.pm \
src/setting/Match.pm \
src/setting/Object.pm \
Expand Down
53 changes: 0 additions & 53 deletions src/classes/IO.pir
Expand Up @@ -26,20 +26,7 @@ This file implements the IO file handle class.

=over 4

=item close

Closes the file.

=cut

.namespace ['IO']
.sub 'close' :method
.local pmc pio
pio = getattribute self, "$!PIO"
close pio
.return(1)
.end


=item eof

Expand Down Expand Up @@ -89,30 +76,6 @@ See also slurp.
.end


=item print

Writes the given list of items to the file.

=cut

.namespace ['IO']
.sub 'print' :method
.param pmc args :slurpy
.local pmc it
.local pmc pio
pio = getattribute self, "$!PIO"
args = 'list'(args)
it = iter args
iter_loop:
unless it goto iter_end
$S0 = shift it
print pio, $S0
goto iter_loop
iter_end:
.return (1)
.end


=item printf

Parses a format string and prints formatted output according to it.
Expand Down Expand Up @@ -142,22 +105,6 @@ Reads a line from the file handle.
.end


=item say

Writes the given list of items to the file, then a newline character.

=cut

.sub 'say' :method
.param pmc list :slurpy
.local pmc pio
pio = getattribute self, "$!PIO"
self.'print'(list)
print pio, "\n"
.return (1)
.end


=item slurp

Slurp a file into a string.
Expand Down
32 changes: 32 additions & 0 deletions src/setting/IO.pm
@@ -0,0 +1,32 @@
class IO is also {

multi method close() is export {
try {
?$!PIO.close()
}
$! ?? fail($!) !! Bool::True
}

multi method print(*@items) is export {
try {
$!PIO.print($_) for @items;
}
$! ?? fail($!) !! Bool::True
}

multi method say(*@items) is export {
my $print_res = self.print(|@items);
if $print_res {
try {
$!PIO.print("\n");
}
return $! ?? fail($!) !! Bool::True
}
else {
return $print_res;
}
}

}

# vim: ft=perl6

0 comments on commit 7b9f811

Please sign in to comment.