Name

CatalystX::Usul::Utils - Base class utility methods for models and programs

Version

0.3.$Revision: 576 $

Synopsis

package CatalystX::Usul::Model;

use parent qw(CatalystX::Usul CatalystX::Usul::Utils);

package YourApp::Model::YourModel;

use parent qw(CatalystX::Usul::Model);

Description

Provides utility methods to the model and program base classes

Subroutines/Methods

child_list

@pids = $self->child_list( $pid );

Called with a process id for an argument this method returns a list of child process ids

cleaner

This interrupt handler traps the pipe signal

handler

This interrupt handler traps the child signal

popen

$response = $self->popen( $cmd, @input );

Uses IPC::Open3 to fork a command and pipe the lines of input into it. Returns a CatalystX::Usul::Response object. The response object's out method returns the STDOUT from the command. Throws in the event of an error

process_exists

$bool = $self->process_exists( file => $path, pid => $pid );

Tests for the existence of the specified process. Either specify a path to a file containing the process id or specify the id directly

run_cmd

$response = $self->run_cmd( $cmd, $args );

Runs the given command by calling system. The keys of the $args hash are:

async

If async is true then the command is run in the background

debug

Debug status. Defaults to $self->debug

err

Passing err => q(out) mixes the normal and error output together

log

Logging object. Defaults to $self->log

tempdir

Directory used to store the lock file and lock table if the fcntl backend is used. Defaults to $self->tempdir

Returns a CatalystX::Usul::Response object or throws an error. The response object has the following methods:

core

Returns true if the command generated a core dump

err

Contains a cleaned up version of the command's STDERR

out

Contains a cleaned up version of the command's STDOUT

rv

The return value of the command

sig

If the command died as the result of receiving a signal return the signal number

stderr

Contains the command's STDERR

stdout

Contains the command's STDOUT

send_email

$result = $self->send_email( $args );

Sends emails. The $args hash ref uses these keys:

attachments

A hash ref whose key/value pairs are the attachment name and path name. Encoding and content type are derived from the file name extension

attributes

A hash ref that is applied to email when it is created. Typical keys are; content_type and charset

body

Text for the body of the email message

from

Email address of the sender

mailer

Which mailer should be used to send the email. Defaults to SMTP

mailer_host

Which host should send the email. Defaults to localhost

stash

Hash ref used by the template rendering to supply values for variable replacement

subject

Subject string

template

If it exists then the template is rendered and used as the body contents

to

Email address of the recipient

signal_process

$self->signal_process( [{] param => value, ... [}] );

This is called by processes running as root to send signals to selected processes. The passed parameters can be either a list of key value pairs or a hash ref. Either a single pid, or an array ref pids, or file must be passwd. The file parameter should be a path to a file containing pids one per line. The sig defaults to TERM. If the flag parameter is set to one then the given signal will be sent once to each selected process. Otherwise each process and all of it's children will be sent the signal. If the force parameter is set to true the after a grace period each process and it's children are sent signal KILL

Diagnostics

None

Configuration and Environment

None

Dependencies

CatalystX::Usul::Base
CatalystX::Usul::Response
Email::Send
Email::MIME
Email::MIME::Creator
IPC::Open3
IPC::SysV
MIME::Types
POSIX
Proc::ProcessTable
Template

Incompatibilities

There are no known incompatibilities in this module

Bugs and Limitations

There are no known bugs in this module. Please report problems to the address below. Patches are welcome

Author

Peter Flanigan, <Support at RoxSoft.co.uk>

License and Copyright

Copyright (c) 2008 Peter Flanigan. All rights reserved

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic

This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE