home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / perl / 5.8.8 / IO / File.pm < prev    next >
Encoding:
Perl POD Document  |  2006-07-07  |  1.7 KB  |  87 lines

  1. #
  2.  
  3. package IO::File;
  4.  
  5. use 5.006_001;
  6. use strict;
  7. our($VERSION, @EXPORT, @EXPORT_OK, @ISA);
  8. use Carp;
  9. use Symbol;
  10. use SelectSaver;
  11. use IO::Seekable;
  12. use File::Spec;
  13.  
  14. require Exporter;
  15.  
  16. @ISA = qw(IO::Handle IO::Seekable Exporter);
  17.  
  18. $VERSION = "1.13";
  19.  
  20. @EXPORT = @IO::Seekable::EXPORT;
  21.  
  22. eval {
  23.     # Make all Fcntl O_XXX constants available for importing
  24.     require Fcntl;
  25.     my @O = grep /^O_/, @Fcntl::EXPORT;
  26.     Fcntl->import(@O);  # first we import what we want to export
  27.     push(@EXPORT, @O);
  28. };
  29.  
  30. ################################################
  31. ## Constructor
  32. ##
  33.  
  34. sub new {
  35.     my $type = shift;
  36.     my $class = ref($type) || $type || "IO::File";
  37.     @_ >= 0 && @_ <= 3
  38.     or croak "usage: new $class [FILENAME [,MODE [,PERMS]]]";
  39.     my $fh = $class->SUPER::new();
  40.     if (@_) {
  41.     $fh->open(@_)
  42.         or return undef;
  43.     }
  44.     $fh;
  45. }
  46.  
  47. ################################################
  48. ## Open
  49. ##
  50.  
  51. sub open {
  52.     @_ >= 2 && @_ <= 4 or croak 'usage: $fh->open(FILENAME [,MODE [,PERMS]])';
  53.     my ($fh, $file) = @_;
  54.     if (@_ > 2) {
  55.     my ($mode, $perms) = @_[2, 3];
  56.     if ($mode =~ /^\d+$/) {
  57.         defined $perms or $perms = 0666;
  58.         return sysopen($fh, $file, $mode, $perms);
  59.     } elsif ($mode =~ /:/) {
  60.         return open($fh, $mode, $file) if @_ == 3;
  61.         croak 'usage: $fh->open(FILENAME, IOLAYERS)';
  62.     }
  63.     if (defined($file) && length($file)
  64.         && ! File::Spec->file_name_is_absolute($file))
  65.     {
  66.         $file = File::Spec->rel2abs($file);
  67.     }
  68.     $file = IO::Handle::_open_mode_string($mode) . " $file\0";
  69.     }
  70.     open($fh, $file);
  71. }
  72.  
  73. ################################################
  74. ## Binmode
  75. ##
  76.  
  77. sub binmode {
  78.     ( @_ == 1 or @_ == 2 ) or croak 'usage $fh->binmode([LAYER])';
  79.  
  80.     my($fh, $layer) = @_;
  81.  
  82.     return binmode $$fh unless $layer;
  83.     return binmode $$fh, $layer;
  84. }
  85.  
  86. 1;
  87.