NAME
Linux::Sysfs::Attribute - sysfs attributes
SYNOPSIS
my $attr = Linux::Sysfs::Attributes->open($path);
if ($attr->can_read) {
$attr->read;
printf "%s: %s\n", $attr->name, $attr->value;
}
if ($attr->can_write) {
printf "Writing %s to %s at %s\n",
$new_value, $attr->name, $attr->path;
$attr->write($new_value);
}
$attr->close;
DESCRIPTION
A file in sysfs represents a device or driver attribute Attributes can be read only, write only, or read and write. File data can be ASCII and binary.
METHODS
- open
-
my $attr = Linux::Sysfs::Attribute->open($path);
Opens up a file in sysfs and creates a Linux::Sysfs::Attribute instance. File isn't read with this function.
$path
is the File/Attribute's path. Returns a Linux::Sysfs::Attribute object on success or undef on failure. - close
-
$attr->close;
Cleans up and closes sysfs_attribute structure.
- read
-
$attr->read or die 'read failed';
Reads the supplied attribute. Since the maximum transfer from a sysfs attribute is a pagesize, function reads in up to a page from the file and stores it in Linux::Sysfs::Attribute object to be retrieved with
$attr->value
. Returns something true on success or something false on failure. - write
-
$attr->write($value) or die 'write failed';
Writes to the supplied attribute. Function validates if the given attribute is writable, and writes the new value to the attribute. The user needs to supply the
$value
to be written. Returns something true on success or something false on failure. - value
-
my $value = $attr->value;
Returns the value of the attribute. You need to call read() or write() first to use this method.
- can_read
-
my $can_read = $attr->can_read;
Returns something true if the attribute is readable, false otherwise.
- can_write
-
my $can_write = $attr->can_write;
Returns something true if the attribute is writable, false otherwise.
- name
-
my $name = $attr->name;
Returns the attributes name.
- path
-
my $path = $attr->path;
The path returned by this method represents the file/attribute's full path.
AUTHOR
Florian Ragwitz <rafl@debian.org>
COPYRIGHT & LICENSE
Copyright 2006 Florian Ragwitz, all rights reserved.
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA.