Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions lib/Bencode.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use 5.006;
use strict;
use warnings;

package Bencode;
our $VERSION = '1.502';
Expand Down Expand Up @@ -121,7 +120,7 @@ sub _bencode;
sub _bencode {
map
+( ( not defined ) ? ( $undef_encoding or croak 'unhandled data type' )
: ( not ref ) ? ( m/\A (?: 0 | -? [1-9] \d* ) \z/x ? 'i' . $_ . 'e' : length . ':' . $_ )
: ( not ref ) ? ( ("" & $_) ne "" ? 'i' . $_ . 'e' : length . ':' . $_ )
: ( 'SCALAR' eq ref ) ? ( length $$_ ) . ':' . $$_ # escape hatch -- use this to avoid num/str heuristics
: ( 'ARRAY' eq ref ) ? 'l' . ( join '', _bencode @$_ ) . 'e'
: ( 'HASH' eq ref ) ? 'd' . do { my @k = sort keys %$_; join '', map +( length $k[0] ) . ':' . ( shift @k ) . $_, _bencode @$_{ @k } } . 'e'
Expand Down Expand Up @@ -297,10 +296,4 @@ The format does not support this.

=back

=head1 BUGS AND LIMITATIONS

Strings and numbers are practically indistinguishable in Perl, so C<bencode()>
has to resort to a heuristic to decide how to serialise a scalar. This cannot
be fixed.

=cut