Module::New::Recipe - Module::New::Recipe documentation


Module-New documentation Contained in the Module-New distribution.

Index


Code Index:

NAME

Top

Module::New::Recipe

SYNOPSIS

Top

  package Your::Module::New::Recipe::Something;
  use strict;
  use warnings;
  use Module::New::Recipe;
  use Module::New::Command::Basic;

  available_options ();

  flow {
    guess_root;

    loop {
      do_something;
    };
  };

  1;

DESCRIPTION

Top

This is a base class which provides basic DSLish commands to define recipes. See also Module::New::Command::Basic.

FUNCTIONS TO DEFINE RECIPES

Top

available_options

defines command line option specifications which will be passed to Getopt::Long::Parser.

flow

defines a recipe/command flow. All the commands in the flow would take $self and all the arguments passed through the command line.

loop

defines an internal loop. All the commands in the loop would take $self and an argument per iteration.

AUTHOR

Top

Kenichi Ishigaki, <ishigaki@cpan.org>

COPYRIGHT AND LICENSE

Top


Module-New documentation Contained in the Module-New distribution.

package Module::New::Recipe;

use strict;
use warnings;
use Carp;
use Module::New::Meta;
use Module::New::Queue;

my @options;

functions {
  flow => sub (&) {
    my $flow = shift;
    Module::New::Queue->register(sub {
      my ($self, @args) = @_;
      Module::New::Queue->localize(sub {
        $flow->();
        Module::New::Queue->consume( $self, @args );
      })
    })
  },

  loop => sub (&) {
    my $loop = shift;
    Module::New::Queue->register(sub {
      my ($self, @args) = @_;
      Module::New::Queue->localize(sub {
        $loop->();
        foreach my $arg ( @args ) {
          Module::New::Queue->consume( $self, $arg );
        }
      });
    });
  },

  available_options => sub (@) { @options = @_ },
};

methods {
  options => sub { @options },

  run => sub {
    my ($self, @args) = @_;
    Module::New::Queue->consume( $self, @args );
  }
};

1;

__END__