Android-ElectricSheep-Automator

 view release on metacpan or  search on metacpan

lib/Android/ElectricSheep/Automator/Plugins/Apps/Base.pm  view on Meta::CPAN

	$log->short(1);

	my $v;
	if( exists($params->{'verbosity'}) && defined($params->{'verbosity'}) ){
		$v = $params->{'verbosity'};
	} elsif( exists($confighash->{'debug'}) && exists($confighash->{'debug'}->{'verbosity'}) && defined($confighash->{'debug'}->{'verbosity'}) ){
		$v = $confighash->{'debug'}->{'verbosity'};
	} else {
		$v = $self->mother()->verbosity;
	}

	if( $self->verbosity($v) < 0 ){ $log->error("${whoami} (via $parent), line ".__LINE__." : error, call to 'verbosity()' has failed for value '$v'."); return 1 }

	if( exists($params->{'cleanup'}) && defined($params->{'cleanup'}) ){
		$v = $params->{'cleanup'};
	} elsif( exists($confighash->{'debug'}) && exists($confighash->{'debug'}->{'cleanup'}) && defined($confighash->{'debug'}->{'cleanup'}) ){
		$v = $confighash->{'debug'}->{'cleanup'};
	} else {
		$v = $self->mother()->cleanup;
	}
	if( $self->cleanup($v) < 0 ){ $log->error("${whoami} (via $parent), line ".__LINE__." : error, call to 'cleanup()' has failed for value '$v'."); return 1 }

	# optional params to overwrite confighash settings,
	# defaults exist above or in the configfile
	if( exists($params->{'verbosity'}) && defined($params->{'verbosity'}) ){ $self->verbosity($params->{'verbosity'}) } # later we will call verbosity()
	if( exists($params->{'cleanup'}) && defined($params->{'cleanup'}) ){ $self->cleanup($params->{'cleanup'}) }
	else { $self->cleanup($confighash->{'debug'}->{'cleanup'}) }

	if( $self->verbosity > 0 ){ $log->info("${whoami} (via $parent), line ".__LINE__." : ".__PACKAGE__." has been initialised ...") }

	return 0 # success
}

# only pod below
=pod

=head1 NAME

Android::ElectricSheep::Automator::Plugins::Apps::Base - base class for our plugins

=head1 VERSION

Version 0.09


=head1 SYNOPSIS

This is the parent class of all L<Android::ElectricSheep::Automator>
plugins. You do not need to override anything except perhaps the
constructor if you are going to be needing extra input parameters
to it. There is already one plugin provided L<Android::ElectricSheep::Automator::Plugins::Apps::Viber>
which can serve as an example for creating new plugins.
It is as simple as this:

    package Android::ElectricSheep::Automator::Plugins::Apps::MyNewPlugin;

    use parent 'Android::ElectricSheep::Automator::Plugins::Apps::Base';

    sub new {
            my ($class, $params) = @_;  
            my $self = $class->SUPER::new({
                    %$params,
                    'child-class' => $class,
            });
            # add some extra internal fields, e.g. the name of the app
            # we are dealing with
            $self->{'_private'}->{'appname'} = 'com.viber.voip';
    
            return $self;
    }
    # new methods
    # getter of the app name
    sub appname { return $_[0]->{'_private'}->{'appname'} }
    # any methods for controlling the app, e.g.
    sub open_viber_app {
        my ($self, $params) = @_;
        ...
    }
    ...

Then use the plugin as:

   use Android::ElectricSheep::Automator::Plugins::Apps::MyNewPlugin;
   my $vib = Android::ElectricSheep::Automator::Plugins::Apps::MyNewPlugin->new({
     configfile=>'config/plugins/viber.conf',
     'device-is-connected' => 1
   });
   $vib->open_app();
   $vib->is_app_running() or ...;
   $vib->send_message({recipient=>'My Notes', message=>'hello%sMonkees'});
   $vib->close_app();

=head1 AUTHOR

Andreas Hadjiprocopis, C<< <bliako at cpan.org> >>

=head1 BUGS

Please report any bugs or feature requests to C<bug-android-adb-automator at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Android-ADB-Automator>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.




=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Android::ElectricSheep::Automator::Plugins::Apps::Base


You can also look for information at:

=over 4

=item * RT: CPAN's request tracker (report bugs here)

L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Android-ADB-Automator>

=item * CPAN Ratings



( run in 0.990 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )