App-Device-Chip-sensor
view release on metacpan or search on metacpan
lib/App/Device/Chip/sensor.pm view on Meta::CPAN
$_chipname_width, $chipname, $_sensorname_width, $sensor->name, $valuestr;
}
}
=head1 REQUIRED METHODS
This base class itself is incomplete, requiring the following methods to be
provided by an implementing subclass to contain the actual application logic.
=cut
=head2 output_readings
$app->output_readings( $now, $sensors, $values );
This method is invoked regularly by the L</run> method, to provide the
application with the latest round of sensor readings. It is passed the current
UNIX epoch timestamp as C<$now>, an array reference containing the individual
L<Device::Chip::Sensor> instances as C<$sensors>, and a congruent array
reference containing the most recent readings taken from them, as plain
numbers.
The application should put the bulk of its processing logic in here, for
example writing the values to some sort of file or database, displaying them
in some form, or whatever else the application is supposed to do.
=cut
=head1 OVERRIDABLE METHODS
The base class provides the following methods, but it is expected that
applications may wish to override them to customise the logic contained in
them.
If using L<Object::Pad> to do so, don't forget to provide the C<:override>
method attribute.
=cut
=head2 OPTSPEC
%optspec = $app->OPTSPEC;
This method is invoked by the L</parse_argv> method to construct a definition
of the commandline options understood by the program. These are returned in a
key/value list to be processed by L<Getopt::Long>. If the application wishes
to parse additional arguments it should override this method, call the
superclass version, and append any extra argument specifications it requires.
As this is invoked as a regular instance method, a convenient way to store the
parsed values is to pass references to instance slot variables created by the
L<Object::Pad> C<field> keyword:
field $_title;
field $_bgcol = "#cccccc";
method OPTSPEC :override
{
return ( $self->SUPER::OPTSPEC,
'title=s' => \$_title,
'background-color=s' => \$_bgcol,
);
}
=cut
=head2 after_sensors
await $app->after_sensors( @sensors );
This method is invoked once on startup by the L</run> method, after it has
configured the chip adapter and chips and obtained their individual sensor
instances. The application may wish to perform one-time startup tasks in here,
such as creating database files with knowledge of the specific sensor data
types, or other such behaviours.
=cut
=head2 on_sensor_ok
$app->on_sensor_ok( $sensor );
This method is invoked in C<--best-effort> mode after a successful reading
from sensor; typically this is used to clear a failure state.
The default implementation does nothing.
=cut
method on_sensor_ok ( $sensor ) { }
=head2 on_sensor_fail
$app->on_sensor_fail( $sensor, $failure );
This method is invoked in C<--best-effort> mode after a failure of the given
sensor. The caught exception is passed as C<$failure>.
The default implementation prints this as a warning using the core C<warn()>
function.
=cut
method on_sensor_fail ( $sensor, $failure )
{
my $sensorname = $sensor->name;
my $chipname = ref ( $sensor->chip );
warn "Unable to read ${sensorname} of ${chipname}: $failure";
}
=head1 FILTERING
The C<--filter> setting accepts the following filter names
=cut
=head2 null
No filtering is applied. Each sensor reading is reported as it stands.
( run in 1.576 second using v1.01-cache-2.11-cpan-d8267643d1d )