4 use vars qw($VERSION @ISA @EXPORT);
9 @ISA = qw(Exporter DynaLoader);
10 # Items to export into callers namespace by default. Note: do not export
11 # names by default without a very good reason. Use EXPORT_OK instead.
12 # Do not simply export all your public functions/methods/constants.
18 bootstrap OS2::ExtAttr $VERSION;
20 # Preloaded methods go here.
22 # Format of the array:
23 # 0 ead, 1 file name, 2 file handle. 3 length, 4 position, 5 need to write.
27 my $ea = _create() || die "Cannot create EA: $!";
30 if (ref $file eq 'GLOB' or ref \$file eq 'GLOB') {
31 die "File handle is not opened" unless $handle = fileno $file;
32 _read($ea, undef, $handle, 0);
35 _read($ea, $name, 0, 0);
37 bless [$ea, $name, $handle, 0, 0, 0], $class;
42 # 0 means: discard eas which are not in $eas->[0].
43 _write( $eas->[0], $eas->[1], $eas->[2], 0) and die "Cannot write EA: $!"
45 _destroy( $eas->[0] );
50 $eas->[3] = _count($eas->[0]);
52 return undef if $eas->[4] > $eas->[3];
53 return _get_name($eas->[0], $eas->[4]);
59 return undef if $eas->[4] > $eas->[3];
60 return _get_name($eas->[0], $eas->[4]);
65 my $index = _find($eas->[0], shift);
66 return undef if $index <= 0;
67 return value($eas->[0], $index);
72 return _find($eas->[0], shift) > 0;
78 add($eas->[0], shift, shift) > 0 or die "Error setting EA: $!";
83 my $index = _find($eas->[0], shift);
84 return undef if $index <= 0;
85 my $value = value($eas->[0], $index);
86 _delete($eas->[0], $index) and die "Error deleting EA: $!";
97 # Here are additional methods:
105 if (ref $file eq 'GLOB' or ref \$file eq 'GLOB') {
106 die "File handle is not opened" unless $handle = fileno $file;
107 _write($eas->[0], undef, $handle, 0) or die "Cannot write EA: $!";
110 _write($eas->[0], $name, 0, 0) or die "Cannot write EA: $!";
116 # 0 means: discard eas which are not in $eas->[0].
117 _write( $eas->[0], $eas->[1], $eas->[2], 0) and die "Cannot write EA: $!";
120 # Autoload methods go after =cut, and are processed by the autosplit program.
124 # Below is the stub of documentation for your module. You better edit it!
128 OS2::ExtAttr - Perl access to extended attributes.
133 tie %ea, 'OS2::ExtAttr', 'my.file';
135 $ea{myfield} = 'value';
141 The package provides low-level and high-level interface to Extended
142 Attributes under OS/2.
144 =head2 High-level interface: C<tie>
146 The only argument of tie() is a file name, or an open file handle.
148 Note that all the changes of the tied hash happen in core, to
149 propagate it to disk the tied hash should be untie()ed or should go
150 out of scope. Alternatively, one may use the low-level C<update>
151 method on the corresponding object. Example:
155 Note also that setting/getting EA flag is not supported by the
156 high-level interface, one should use the low-level interface
157 instead. To use it on a tied hash one needs undocumented way to find
158 C<eas> give the tied hash.
160 =head2 Low-level interface
162 Two low-level methods are supported by the objects: copy() and
163 update(). The copy() takes one argument: the name of a file to copy
164 the attributes to, or an opened file handle. update() takes no
165 arguments, and is discussed above.
167 Three convenience functions are provided:
170 add($eas, $key, $value [, $flag])
171 replace($eas, $key, $value [, $flag])
173 The default value for C<flag> is 0.
175 In addition, all the C<_ea_*> and C<_ead_*> functions defined in EMX
176 library are supported, with leading C<_ea/_ead> stripped.
180 Ilya Zakharevich, ilya@math.ohio-state.edu