App-Device-Chip-sensor

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


    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 Object::Pad field keyword:

       field $_title;
       field $_bgcol = "#cccccc";
    
       method OPTSPEC :override
       {
          return ( $self->SUPER::OPTSPEC,
             'title=s'            => \$_title,
             'background-color=s' => \$_bgcol,
          );
       }

 after_sensors

       await $app->after_sensors( @sensors );

    This method is invoked once on startup by the "run" method, after it

bin/device-chip-sensor  view on Meta::CPAN


Prints all the values of each chip's configuration (according to the
C<read_config> method) on startup.

=back

=cut

   method OPTSPEC :override
   {
      return $self->SUPER::OPTSPEC, (
         'p|print-config' => \$_PRINT_CONFIG,
      );
   }

   async method after_sensors :override ( @sensors )
   {
      my @chips = await $self->chips;

      if( $_PRINT_CONFIG ) {
         foreach my $chip ( @chips ) {

bin/device-chip-sensor-datalogger  view on Meta::CPAN

A strftime(3) format string to use for writing the initial timestamp column.

Defaults to C<"%Y-%m-%d %H:%M:%S">.

=back

=cut

   method OPTSPEC :override
   {
      return $self->SUPER::OPTSPEC, (
         'o|output=s' => \$_OUTFILE,

         'timestamp=s'  => \$_TIMESTAMP,
      );
   }

   field $_csv;
   field $_outh;

   async method after_sensors :override ( @sensors )

bin/device-chip-sensor-exporter  view on Meta::CPAN

my $STRFTIME = "%Y-%m-%d %H:%M:%S";

class MyApp :isa(App::Device::Chip::sensor)
{
   use Carp;
   use POSIX qw( strftime );
   use Scalar::Util qw( refaddr reftype );

   method OPTSPEC
   {
      return $self->SUPER::OPTSPEC, (
         'port=i'     => \$PORT,
         'verbose+'   => \$VERBOSE,
         'config|c=s' => sub { $self->read_config_file( $_[1] ); },
      );
   }

   method read_config_file ( $path )
   {
      require YAML;

bin/device-chip-sensor-exporter  view on Meta::CPAN

            die "This sensor chip has failed 5 times in a row; aborting\n";
         }
         if( keys %chip_failures >= 3 ) {
            die "Three or more sensor chips have failed; aborting\n";
         }
      }
      undef %failures_per_chip;
   }

   method on_sensor_fail ( $sensor, $failure ) {
      $self->SUPER::on_sensor_fail( $sensor, $failure );

      my $chip = $sensor->chip;
      my $chipname = ( ref $chip ) =~ s/^Device::Chip:://r;

      $metrics->inc_counter( chip_failures => [ chip => $chipname ] );

      $failures_per_chip{ refaddr $chip } = 1;
   }

   method on_sensor_ok ( $sensor ) {

lib/App/Device/Chip/sensor.pm  view on Meta::CPAN


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 );

t/10args.t  view on Meta::CPAN

use Test2::V0;

use Object::Pad 0.800;

my $customarg;

class TestApp :isa(App::Device::Chip::sensor)
{
   method OPTSPEC
   {
      return ( $self->SUPER::OPTSPEC,
         "custom=s" => \$customarg,
      );
   }
}

BEGIN {
   $INC{"Device/Chip/Adapter/_ATestAdapter.pm"} = __FILE__;
   $ENV{DEVICE_CHIP_ADAPTER} = "_ATestAdapter";
}



( run in 1.244 second using v1.01-cache-2.11-cpan-49f99fa48dc )