---
name: "Message::Passing::Role::Script"
section: "3pm"
platform: "linux"
package: "libmessage-passing-perl"
version: "0.117-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Message::Passing::Role::Script"
---

# Message::Passing::Role::Script(3pm)

Handy role for building messaging scripts.

## NAME

Message::Passing::Role::Script - Handy role for building messaging scripts.

## SYNOPSIS

```
    # my_message_passer.pl
    package My::Message::Passer;
    use Moo;
    use MooX::Options;
    use MooX::Types::MooseLike::Base qw/ Bool /;
    use Message::Passing::DSL;
    with 'Message::Passing::Role::Script';
    option foo => (
        is => 'ro',
        isa => Bool,
    );
    sub build_chain {
        my $self = shift;
        message_chain {
            input example => ( output_to => 'test_out', .... );
            output test_out => ( foo => $self->foo, ... );
        };
    }
    __PACKAGE__->start unless caller;
    1;
```

## DESCRIPTION

This role can be used to make simple message passing scripts.

The user implements a MooX::Options type script class, with a `"build_chain"` method, that builds one or more Message::Passing chains and returns them.

```
    __PACKAGE__->start unless caller;
```

is then used before the end of the script.

This means that when the code is run as a script, it'll parse the command line options, and start a message passing server..

## REQUIRED METHODS

## build\_chain

Return a chain of message processors, or an array reference with multiple chains of message processors.

## ATTRIBUTES

### daemonize

Do a double fork and lose controlling terminal.

Used to run scripts in the background.

### io\_priority

The IO priority to run the script at..

Valid values for the IO priority are:

- none

  - be

  - rt

  - idle

  ### user

Changes the user the script is running as. You probably need to run the script as root for this option to work.

### pid\_file

Write a pid file out. Useful for running Message::Passing scripts as daemons and/or from init.d scripts.

## METHODS

### start

Called as a class method, it will build the current class as a command line script (parsing ARGV), setup the daemonization options, call the -\>build\_chain method supplied by the user to build the chains needed for this application.

Then enters the event loop and never returns.

### change\_uid\_if\_needed

Tries to change uid if the --user option has been supplied

### daemonize\_if\_needed

Tires to daemonize if the --daemonize option has been supplied

### set\_io\_priority\_if\_needed

Tries to set the process' IO priority if the --io\_priority option has been supplied.

## SPONSORSHIP

This module exists due to the wonderful people at Suretec Systems Ltd. \<http://www.suretecsystems.com/\> who sponsored its development for its VoIP division called SureVoIP \<http://www.surevoip.co.uk/\> for use with the SureVoIP API - \<http://www.surevoip.co.uk/support/wiki/api\_documentation\>

## AUTHOR, COPYRIGHT AND LICENSE

See Message::Passing.
