Bluetooth-Any
view release on metacpan or search on metacpan
0.002 2018-10-24 (PERLANCAR)
- [bugfix] Fix checking bluetooth status, differentiate case of not
finding /blocked: no/ as an error condition.
0.001 2018-10-22 (PERLANCAR)
- First release.
lib/Bluetooth/Any.pm view on Meta::CPAN
{
unless (which("rfkill")) {
log_trace "Cannot find rfkill, skipping using rfkill";
last;
}
log_trace "Using rfkill to check bluetooth status";
my $out;
system {capture_stdout=>\$out}, "rfkill", "list", "bluetooth";
last if $?;
my $in_bt;
my $unblocked;
for (split /^/m, $out) {
if (/^\d/) {
if (/bluetooth/i) {
$in_bt = 1;
} else {
$in_bt = 0;
}
next;
} else {
if (/blocked:\s*yes/i) {
return [200, "OK", 0, {'func.method'=>'rfkill', 'cmdline.result'=>'Bluetooth is OFF', 'cmdline.exit_code'=>1}];
} elsif (/blocked:\s*no/i) {
$unblocked = 0;
}
}
}
if (defined $unblocked) {
return [200, "OK", 1, {'func.method'=>'rfkill', 'cmdline.result'=>'Bluetooth is on', 'cmdline.exit_code'=>0}];
} else {
log_warn "Cannot detect 'blocked: no' from 'rfkill list' output, skipping using rfkill";
last;
}
}
[500, "Failed, no methods succeeded"];
}
1;
# ABSTRACT: Common interface to bluetooth functions
__END__
( run in 0.644 second using v1.01-cache-2.11-cpan-49f99fa48dc )