8
今天我装Rakudo星2012.07和tryed写一个简单的Perl脚本6:奇怪的行为6
#!/usr/bin/env perl6
use v6;
use LWP::Simple;
my $html = LWP::Simple.get('http://perl6.org');
say $html;
它不会因为出现以下错误的工作:
No such method 'get_string' for invocant of type 'String'
in method decode at src/gen/CORE.setting:6766
in method parse_response at lib/LWP/Simple.pm:244
in method make_request at lib/LWP/Simple.pm:199
in method request_shell at lib/LWP/Simple.pm:63
in method get at lib/LWP/Simple.pm:28
代码LWP的::上线244简单就是:
my @header_lines = $resp.subbuf(
0, $header_end_pos
).decode('ascii').split(/\r\n/);
奇怪的是,下面的代码是OK:
> Buf.new(1,2,3,4,5).decode('ascii')
,而这一个失败:
> Buf.new(1,2,3,4,5).subbuf(0,3).decode('ascii')
Method 'get_string' not found for invocant of class 'String'
你能解释我请,为什么会发生?据我所见,在这两种情况下Buf.decode方法被调用:
> Buf.new(1,2,3,4,5).subbuf(0,3).isa('Buf')
True
> Buf.new(1,2,3,4,5).isa('Buf')
True
也许这是Rakudo Perl中的一个错误?或者,也许subbuf是一个过时的/无证的方法?它不在doc.perl6.org上。在这种情况下应该使用哪种方法?
你可能会想要问的IRC,通道#perl6。 参见:http://irclog.perlgeek.de/perl6/today –