App-Device-Chip-sensor
view release on metacpan or search on metacpan
lib/App/Device/Chip/sensor.pm view on Meta::CPAN
=cut
field @_CHIPCONFIGS;
method _chipconfigs { @_CHIPCONFIGS } # for unit testing
field $_interval :mutator = 10;
field $_best_effort :mutator;
field $_filter :mutator;
method OPTSPEC
{
return (
'b|blib' => sub { require blib; blib->import; },
'i|interval=i' => \$_interval,
'F|filter=s' => \$_filter,
'm|mid3' => sub { $_filter = "mid3" },
'B|best-effort' => \$_best_effort,
);
}
=head1 PROVIDED METHODS
The following methods are provided on the base class, intended for subclasses
or applications to invoke.
=cut
=head2 parse_argv
$app->parse_argv();
$app->parse_argv( \@argv );
Provides a list of commandline arguments for parsing, either from a given
array reference or defaulting to the process C<@ARGV> if not supplied.
This uses L</OPTSPEC> to collect the defined arguments, whose references
should handle the results.
=cut
method parse_argv ( $argv = \@ARGV )
{
my %optspec = $self->OPTSPEC;
@_CHIPCONFIGS = ();
my $ADAPTERDESC; my $adapter;
GetOptionsFromArray( $argv, %optspec,
'adapter|A=s' => sub {
$ADAPTERDESC = $_[1];
undef $adapter;
},
'<>' => sub {
my ( $chiptype, $opts ) = split m/:/, $_[0], 2;
$adapter //= Device::Chip::Adapter->new_from_description( $ADAPTERDESC );
my %config = (
type => $chiptype,
adapter => $adapter,
);
while( length $opts ) {
if( $opts =~ s/^-C:(.*?)=(.*)(?:$|,)// ) {
$config{config}{$1} = $2;
}
elsif( $opts =~ s/^-M:(.*?)=(.*)(?:$|,)// ) {
$config{mountopts}{$1} = $2;
}
else {
croak "Unable to parse chip configuration options '$opts' for $chiptype'";
}
}
$self->add_chip( %config );
},
) or exit 1;
return $self;
}
=head2 add_chip
$app->add_chip( %config );
I<Since version 0.05.>
Adds a new chip to the stored configuration, as if it had been given as a
commandline argument. Takes the following named arguments:
=over 4
=item type => STR
Required string that gives the name of the chip class.
=item adapter => Device::Chip::Adapter
Required L<Device::Chip::Adapter> instance.
=item mountopts => HASH
Optional HASH reference containing extra mount parameters.
=item config => HASH
Optional HASH reference containing extra chip configuration to set up using
the C<configure> method once mounted.
=back
=cut
extended method add_chip ( :$type, :$adapter, %config )
( run in 0.834 second using v1.01-cache-2.11-cpan-39bf76dae61 )