Oggi ho installato Rakudo Stella 2.012,07 e provato a scrivere un semplice Perl 6 script:strano comportamento di Buf.subbuf in Perl 6
#!/usr/bin/env perl6
use v6;
use LWP::Simple;
my $html = LWP::Simple.get('http://perl6.org');
say $html;
Non funziona a causa del seguente errore:
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
codice di LWP :: Simple on line 244 è:
my @header_lines = $resp.subbuf(
0, $header_end_pos
).decode('ascii').split(/\r\n/);
la cosa strana è che il seguente codice è OK:
> Buf.new(1,2,3,4,5).decode('ascii')
mentre questo non riesce:
> Buf.new(1,2,3,4,5).subbuf(0,3).decode('ascii')
Method 'get_string' not found for invocant of class 'String'
Mi può spiegare per favore, perché succede? Per quanto posso vedere, in entrambi i casi il metodo Buf.decode si chiama:
> Buf.new(1,2,3,4,5).subbuf(0,3).isa('Buf')
True
> Buf.new(1,2,3,4,5).isa('Buf')
True
Forse è un bug in Rakudo Perl? O forse subbuf è un metodo deprecato/non documentato? Non è presente su doc.perl6.org. In questo caso quale metodo dovrebbe essere usato?
Si potrebbe desiderare di chiedere che su IRC, canale # perl6. Vedi: http://irclog.perlgeek.de/perl6/oggi –