Update of /cvsroot/file-extattr/File-ExtAttr/lib/File/ExtAttr
In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv4777/lib/File/ExtAttr
Modified Files:
Tie.pm
Log Message:
Make the tied hash namespace-aware
Index: Tie.pm
===================================================================
RCS file: /cvsroot/file-extattr/File-ExtAttr/lib/File/ExtAttr/Tie.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Tie.pm 6 Mar 2006 20:53:47 -0000 1.2
--- Tie.pm 2 Oct 2006 20:55:42 -0000 1.3
***************
*** 10,14 ****
use Data::Dumper;
! tie %a, "File::ExtAttr::Tie", "/Applications (Mac OS 9)/Sherlock 2";
print Dumper \%a;
--- 10,16 ----
use Data::Dumper;
! tie %a,
! "File::ExtAttr::Tie", "/Applications (Mac OS 9)/Sherlock 2",
! { namespace => 'user' };
print Dumper \%a;
***************
*** 30,33 ****
--- 32,48 ----
the same restrictions as that module in terms of OS support.
+ =head1 METHODS
+
+ =over 4
+
+ =item tie "File::ExtAttr::Tie", $filename, [\%flags]
+
+ The flags are the same optional flags as in File::ExtAttr. Any flags
+ given here will be passed to all operations on the tied hash.
+ Only the C<namespace> flag makes sense. The hash will be tied
+ to the default namespace, if no flags are given.
+
+ =back
+
=cut
***************
*** 39,49 ****
sub TIEHASH {
! my($class, $file) = @_;
! return bless { file => $file }, ref $class || $class;
}
sub STORE {
my($self, $name, $value) = @_;
! return undef unless setfattr($self->{file}, $name, $value);
$value;
}
--- 54,66 ----
sub TIEHASH {
! my($class, $file, $flags) = @_;
! my $self = bless { file => $file }, ref $class || $class;
! $self->{flags} = defined($flags) ? $flags : {};
! return $self;
}
sub STORE {
my($self, $name, $value) = @_;
! return undef unless setfattr($self->{file}, $name, $value, $self->{flags});
$value;
}
***************
*** 51,60 ****
sub FETCH {
my($self, $name) = @_;
! return getfattr($self->{file}, $name);
}
sub FIRSTKEY {
my($self) = @_;
! $self->{each_list} = [listfattr($self->{file})];
shift @{$self->{each_list}};
}
--- 68,77 ----
sub FETCH {
my($self, $name) = @_;
! return getfattr($self->{file}, $name, $self->{flags});
}
sub FIRSTKEY {
my($self) = @_;
! $self->{each_list} = [listfattr($self->{file}, $self->{flags})];
shift @{$self->{each_list}};
}
***************
*** 67,77 ****
sub EXISTS {
my($self, $name) = @_;
! return getfattr($self->{file}, $name) ne undef;
}
sub DELETE {
my($self, $name) = @_;
! my $value = getfattr($self->{file}, $name);
! return $value if delfattr($self->{file}, $name);
undef;
}
--- 84,95 ----
sub EXISTS {
my($self, $name) = @_;
! return getfattr($self->{file}, $name, $self->{flags}) ne undef;
}
sub DELETE {
my($self, $name) = @_;
! # XXX: Race condition
! my $value = getfattr($self->{file}, $name, $self->{flags});
! return $value if delfattr($self->{file}, $name, $self->{flags});
undef;
}
***************
*** 80,84 ****
my($self) = @_;
for(listfattr($self->{file})) {
! delfattr($self->{file}, $_);
}
}
--- 98,102 ----
my($self) = @_;
for(listfattr($self->{file})) {
! delfattr($self->{file}, $_, $self->{flags});
}
}
|