X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FModule%2FMetadata.pm;fp=lib%2FModule%2FMetadata.pm;h=194ce550b69a70750e645d30c5e21a3d7c5d0cff;hb=37dd6c526ef05690e2b23cce32f7faa2a1d3a644;hp=9e32dec022a3236df4463bb9cb6361d1a531751b;hpb=6ae077f7f974541bd2c60fc3ac5d8bdd241b343c;p=p5sagit%2FModule-Metadata.git diff --git a/lib/Module/Metadata.pm b/lib/Module/Metadata.pm index 9e32dec..194ce55 100644 --- a/lib/Module/Metadata.pm +++ b/lib/Module/Metadata.pm @@ -17,7 +17,12 @@ $VERSION = eval $VERSION; use Carp qw/croak/; use File::Spec; -use IO::File; +BEGIN { + # Try really hard to not depend ony any DynaLoaded module, such as IO::File or Fcntl + eval { + require Fcntl; Fcntl->import('SEEK_SET'); 1; + } or *SEEK_SET = sub { 0 } +} use version 0.87; BEGIN { if ($INC{'Log/Contextual.pm'}) { @@ -465,7 +470,7 @@ sub _parse_file { my $self = shift; my $filename = $self->{filename}; - my $fh = IO::File->new( $filename ) + open my $fh, '<', $filename or croak( "Can't open '$filename': $!" ); $self->_handle_bom($fh, $filename); @@ -478,11 +483,11 @@ sub _parse_file { sub _handle_bom { my ($self, $fh, $filename) = @_; - my $pos = $fh->getpos; + my $pos = tell $fh; return unless defined $pos; my $buf = ' ' x 2; - my $count = $fh->read( $buf, length $buf ); + my $count = read $fh, $buf, length $buf; return unless defined $count and $count >= 2; my $encoding; @@ -492,7 +497,7 @@ sub _handle_bom { $encoding = 'UTF-16LE'; } elsif ( $buf eq "\x{EF}\x{BB}" ) { $buf = ' '; - $count = $fh->read( $buf, length $buf ); + $count = read $fh, $buf, length $buf; if ( defined $count and $count >= 1 and $buf eq "\x{BF}" ) { $encoding = 'UTF-8'; } @@ -500,11 +505,10 @@ sub _handle_bom { if ( defined $encoding ) { if ( "$]" >= 5.008 ) { - # $fh->binmode requires perl 5.10 binmode( $fh, ":encoding($encoding)" ); } } else { - $fh->setpos($pos) + seek $fh, $pos, SEEK_SET or croak( sprintf "Can't reset position to the top of '$filename'" ); }