Verby::Action - The base role for an action in Verby.


Verby documentation Contained in the Verby distribution.

Index


Code Index:

NAME

Top

Verby::Action - The base role for an action in Verby.

SYNOPSIS

Top

	package MyAction;
	use Moose;

	with qw/Verby::Action/;

	sub do { ... }

	sub verify { ... }

DESCRIPTION

Top

A Verby::Action is an object encapsulating reusable code. Steps usually delegate to actions, for the actual grunt work.

METHODS

Top

new

Instantiate an action. Actions should be able to live indefinitely, and should not carry internal state with them. All the parameters for do or verify are provided within the context.

The action instance data should only be used to configure action "flavours", controlling behavior that should not be parameter sensitive (configuration data).

do $cxt

The thing that the action really does. For example

	package Verby::Action::Download;

	sub do {
		my ($self, $c) = @_;
		system("wget", "-O", $c->file, $c->url);
	}

Will use wget to download $c->url to $c->file.

This is a bad example though, you ought to subclass Verby::Action::Run if you want to run a command.

verify $cxt

Perform a boolean check - whether or not the action is completed, for a given set of arguments.

For example, if do downloads $c->file from $c->url, then the verify method would look like:

	sub verify {
		my ($self, $c) = @_;
		-f $c->file;
	}

or it could even make a HEAD request and make sure that $c->file is up to date.

confirm $cxt

Typically called at the end of an action's do:

	sub do {
		my ($self, $c) = @_;
		...
		$self->confirm($c);
	}

It will call $c->logger->log_and_die unless verify returns a true value.

If $c->error contains a string then it'll be printed as well.

ASYNCHRONOUS ACTIONS

Top

Since Verby is an abstraction layer over POE and every step get's it's own POE::Session, an actions do method can create child sessions, and the parent session will wait till they are completed, as per default POE behavior.

Note that this documentation assumes delegation of step methods to action methods.

Verby::Dispatcher actually has nothing to do with Verby::Action, it's just that typically a Verby::Step is just a thin wrapper for Verby::Action, so the methods roughly correspond.

See Verby::Step::Closure for a trivial way to generate steps given a Verby::Action subclass.

BUGS

Top

None that we are aware of. Of course, if you find a bug, let us know, and we will be sure to fix it.

CODE COVERAGE

Top

We use Devel::Cover to test the code coverage of the tests, please refer to COVERAGE section of the Verby module for more information.

SEE ALSO

Top

AUTHOR

Top

Yuval Kogman, <nothingmuch@woobling.org>

COPYRIGHT AND LICENSE

Top


Verby documentation Contained in the Verby distribution.

#!/usr/bin/perl

package Verby::Action;
use Moose::Role;

our $VERSION = "0.05";

use Carp qw/longmess/;

requires "do";

requires "verify";

sub confirm {
	my ( $self, $c, @args ) = @_;

	$self->verify($c, @args) or
		$c->logger->log_and_die(level => "error", message => 
			"verification of $self failed: "
			. ($c->error || "error unknown"));
}

__PACKAGE__

__END__