The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MooseX::Role::Cmd - Wrap system command binaries the Moose way

SYNOPSIS

Create your command wrapper:

    package Cmd::Perl;

    use strict;
    use warnings;

    use Moose;

    with 'MooseX::Role::Cmd';

    has 'e' => (isa => 'Str', is => 'rw');

    # other perl switches here...

    1;

Use it somewhere else:

    use Cmd::Perl;

    my $perl = Cmd::Perl->new(e => q{'print join ", ", @ARGV'});
    print $perl->run(qw/foo bar baz/);
    # prints the STDOUT captured from running:
    # perl -e 'print join ", ", @ARGV' foo bar baz

DESCRIPTION

MooseX::Role::Cmd is a Moose role intended to ease the task of building command-line wrapper modules. It automatically maps Moose objects into command strings which are passed to IPC::Cmd.

ATTRIBUTES

$cmd->bin_name

Sets the binary executable name for the command you want to run. Defaults the to last part of the class name.

$cmd->stdout

Returns the STDOUT buffer captured after running the command.

$cmd->stderr

Returns the STDERR buffer captured after running the command.

METHODS

my $bin_name = $cmd->build_bin_name

Builds the default string for the command name based on the class name.

my @stdout = $cmd->run(@args);

Builds the command string and runs it based on the objects current attribute settings. This will treat all the attributes defined in your class as flags to be passed to the command.

Suppose the following setup:

    has 'in'  => (isa => 'Str', is => 'rw')
    has 'out' => (isa => 'Str', is => 'rw');

    # ...

    $cmd->in('foo');
    $cmd->out('bar');

The command will be invoked as:

    cmd -in foo -out bar

All quoting issues are left to be solved by the user.

AUTHOR

Eden Cardim <edencardim@gmail.com>

LICENSE

This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.