2012-08-27 72 views
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上。在这种情况下应该使用哪种方法?

+2

你可能会想要问的IRC,通道#perl6。 参见:http://irclog.perlgeek.de/perl6/today –

回答

6

这是在Rakudo一个bug,已经被固定在最新开发版本

$ perl6 -e 'say Buf.new(1,2,3,4,5).subbuf(0,3).decode("ascii")'|hexdump -C 
00000000 01 02 03 0a          |....| 

(我敢肯定的修复也是Rakudo 2012.08发布,Rakudo星发布基础上,编译器将于本周发布)。

尚未记录的原因是我专注于规范中的那些方法,因为他们有更高的生存机会。尽管如此,我希望尽快添加文档。

更新:抽时间去了,看到http://doc.perl6.org/type/Buf#subbuf