script/electric-sheep-dump-current-location.pl untested

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 84 CC 1 SCAR 6.9
CC
1
Cov
0%
usage
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2  
3 use strict;
4 use warnings;
5  
6 our $VERSION = '0.09';
7  
8 use lib ('blib/lib');
9  
10 use Getopt::Long qw(:config no_ignore_case);
11 use Data::Roundtrip qw/perl2dump perl2json no-unicode-escape-permanently/;
12  
13 use Android::ElectricSheep::Automator;
14  
15 my $VERBOSITY = 0; # we need verbosity of 10 (max), so this is not used
16 my $DEVICE;
17 my $CONFIGFILE;
18 my $OUTFILE;
19  
20 if( ! Getopt::Long::GetOptions(
21 'device|d=s' => \$DEVICE,
22 'verbosity|v=i' => \$VERBOSITY,
23 'output|o=s'=> \$OUTFILE,
24 'configfile|c=s' => \$CONFIGFILE,
25 'help|h' => sub { print STDOUT usage(); exit(0); }
26 ) ){ die usage() }
27  
28 if( ! defined $CONFIGFILE ){ print STDERR usage(); print STDERR "\n$0 : error, a configuration file must be specified with '--configfile'.\n"; exit(1); }
29 if( ! -f $CONFIGFILE ){ die "$0 : failed to find config file '$CONFIGFILE'." }
30  
31 my $params = {
32 'configfile' => $CONFIGFILE,
33 'verbosity' => $VERBOSITY,
34 };
35 # we assume there is a device connected which the user
36 # must specify by serial, of if just one, we connect to
37 # it without the serial
38 if( defined $DEVICE ){ $params->{'device-serial'} = $DEVICE }
39 else { $params->{'device-is-connected'} = 1 }
40  
41 my $client = Android::ElectricSheep::Automator->new($params);
42 if( ! defined($client) ){ die "$0 : failed to instantiate the automator." }
43  
44 my $geo = $client->dump_current_location();
45 if( ! defined($geo) ){ die "$0 : failed to dump current location." }
46  
47 my $jsonstr = perl2json($geo);
48 if( ! defined $jsonstr ){ die perl2dump($geo)."$0 : failed to convert above Perl data structure to JSON." }
49 if( defined $OUTFILE ){
50 my $FH;
51 open($FH, '>', $OUTFILE) or die "$0 : failed to open output file '$OUTFILE' for writing, $!";
52 print $FH $jsonstr;
53 close $FH;
54 } else { print STDOUT $jsonstr }
55  
56 print STDOUT "$0 : done, success!".(defined($OUTFILE)?" Output written to file '$OUTFILE'.\n":"\n");
57  
58 sub usage {
59 return "Usage $0 --configfile CONFIGFILE [--output geolocation.json] [--device DEVICE] [--verbosity v]\n"
60 . "\nThis script will dump the current location of the device, for all its providers, as JSON.\n"
61 . "\nExample:\n"
62 . "$0 --configfile config/myapp.conf --output geolocation.json\n"
63 . "\nProgram by Andreas Hadjiprocopis (c) 2025 / bliako at cpan.org / andreashad2 at gmail.com\n\n"
64 ;
65 }
66  
67 1;