File: WithPath.pm

package info (click to toggle)
libio-file-withpath-perl 0.09-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 192 kB
  • sloc: perl: 1,888; makefile: 2
file content (81 lines) | stat: -rw-r--r-- 1,276 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package IO::File::WithPath;
use strict;
use warnings;
our $VERSION = '0.09';

use base qw/IO::File/;
use File::Spec;

sub new {
    my $class = shift;
    my $path  = File::Spec->rel2abs(shift);

    my $io = IO::File->new($path, @_);

    # symboltable hack
    ${*$io}{+__PACKAGE__} = $path;

    bless $io => $class;
}

sub path { 
    my $io = shift;
    ${*$io}{+__PACKAGE__};
}


1;
__END__

=encoding utf8

=head1 NAME

IO::File::WithPath - An IO::File extension that keeps the pathname

=head1 SYNOPSIS

  use IO::File::WithPath;
  my $io = IO::File::WithPath->new('/path/to/file');
  print $io->path; # print '/path/to/file'
  print $io->getline; # IO::File-method

=head1 DESCRIPTION

IO::File::WithPath is a Perl module extending IO::File to keep track
of the absolute path name.

=head1 METHODS

=over 4

=item new

create object from file-path as IO::File->new().
but file-path not include MODE.(e.g. '</path/to/file')

=item path

file-path

=back

=head1 AUTHOR

Masahiro Chiba E<lt>nihen@megabbs.comE<gt>

=head1 THANKS

miyagawa
nothingmuch

=head1 LICENSE

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=head1 COPYRIGHT

Copyright (c) 2009-2011 Masahiro Chiba E<lt>nihen@megabbs.comE<gt>

=cut