Acpi::Class - Gets ACPI information fom /sys/class directory.
my $class = Acpi::Class->new( class => 'power_supply'); my $devices = $class->g_devices; print "Power devices: "; foreach (@$devices) {print "$_ "} print "\n"; $class->device('AC'); my $ac_online = $class->g_values->{'online'}; $class->device('BAT0'); my $values = $class->g_values; my $battery_present = $values->{'present'}; my $battery_energy_now = $values->{'energy_now'}; my $battery_capacity = $values->{'capacity'}; if ( $ac_online == 1 and $battery_present == 1 ) { say "Ac on and battery in use "; say "Energy now = ". $battery_energy_now ; say "Capacity " . $battery_capacity ." %"; } elsif ($battery_present) { say "Battery in use"; say "Energy now = ". $battery_energy_now ; say "Capacity " . $battery_capacity ." %"; } else { say "Battery not present"; } # get all values of device BAT1 say "-" x 50; $class->p_device_values; say "-" x 50; # get all values of class power_supply $class->p_class_values;
Acpi::Class provides ACPI information from the directory /sys/class. It's specific for GNU/Linux.
Acpi::Class implements the following attributes:
$class = Acpi::Class->new( class => 'thermal');
$class->class('thermal');
Sets the class (directory under /sys/class).
$class = Acpi::Class->new( class => 'thermal', device=> 'BAT0' ));
$class->device('BAT0');
Sets the device (directory under /sys/class/$class).
Acpi::Class implements the following methods:
my $class = Acpi::Class->new( class => 'thermal', device => 'BAT1 );
Object constructor.
my $classes = $class->g_classes;
Gets an ArrayRef of the available classes (directories under /sys/class).
Gets an ArrayRef of available devices (directories under /sys/class/$class).
Gets a Hashef of the attributes and values of a device (content of the files in /sys/class/$class/$device).
$class->class('power_supply'); $class->device('BAT1'); $class->p_device_values;
Prints all the attributes and values of the device BAT1.
$class->class('power_supply'); $class->p_device_values;
Print all the attributes and values of the devices in the class 'power_supply'.
Get involved:
GitHub
Gitorious
The modules Acpi::Battery, Acpi::Fan and Acpi::Temperature get the information from the directory /proc/acpi. This directory is deprecated in Linux kernel 2.6.24 and deleted in 2.6.39.
To install Acpi::Class, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Acpi::Class
CPAN shell
perl -MCPAN -e shell install Acpi::Class
For more information on module installation, please visit the detailed CPAN module installation guide.