Jonathan Rockway > File-Attributes > File::Attributes::Base

Download:
File-Attributes-0.04.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  1
View/Report Bugs
Source  

NAME ^

File::Attributes::Base - Base class for File::Attributes

SYNOPSIS ^

Currently, this class works like a pragma. If something inherits from it, File::Attributes will assume it is trying to implement some sort of file attribute accessor.

   package File::Attributes::MyAccessMethod;
   use base 'File::Attributes::Base';

   sub priority { 5 }

   sub applicable {
     my $self = shift;
     my $file = shift;
     eval {
       $self->list($file);
     }
     return 1 if !$@;
     return 0;
   }

   sub list {
     my $self = shift;
     ...
   }
   ...
   1;

METHODS ^

new

Creates an instance. You probably don't need to override this in your subclass.

priority

Called to determine the order in which various subclasses should be used to get or set an attribute. Classes will be called from highest priority to lowest priority until an attribute is successfully accessed. The priority returned should be an integer between 0 and 10. 1 is reserved for access methods that will work on any system, like File::Attributes::Simple. 10 should be used for plugins that will work for any file on any filesystem for a specific OS. 5 should be used for plugins that may or may not work, like UNIX extended filesystem attributes on UNIX-like systems; see File::Attributes::Extended.

A priority of 0 indicates that the module should not be used at all.

applicable($filename)

Called to determine if this attribute access method works with $filename. Some systems have syscalls for attribute access that may be called on any file, but will fail if the "use attributes" option isn't set on that file's filesystem. In this case, applicable can return false so that an alternate access method is tried.

This method will return true (1) if the class can access attributes for $filename and false (0) otherwise.

METHODS THAT SUBCLASSES SHOULD IMPLEMENT ^

... but aren't required to, because $instance->can('method') will tell whoever's using the module that you're not implementing that method.

get($file, $attribute)

Return the value of $attribute on $file. Throw an exception if something bad happens, like $file doesn't exist, or the filesystem doesn't support your type of attribute.

set($file, $key, $value)

Set the attribute $key to $value on $file. Again, if something bad happpens, croak; don't return undef!

unset($file, $attribute)

Unset the attribute called $attribute. You probably shouldn't throw an exception if $attribute is already undefined, but if it makes sense in your context, feel free to.

list($file)

Return a list of all attributes that $file has.

applicable

Override this so you can return true, otherwise your module will be useless.

AUTHOR ^

Jonathan Rockway <jrockway@cpan.org>.

BUGS ^

Report to RT; see "BUGS" in File::Attributes.

syntax highlighting: