App-Cronjob

 view release on metacpan or  search on metacpan

lib/App/Cronjob.pm  view on Meta::CPAN

sub send_cronjob_report {
  my ($arg) = @_;

  require Email::Simple;
  require Email::Simple::Creator;
  require Email::Sender::Simple;
  require Text::Template;

  my $body     = Text::Template->fill_this_in(
    $TEMPLATE,
    HASH => {
      command => \$opt->{command},
      output  => $arg->{output},
      time    => $arg->{time} || \'(n/a)',
      status  => \($arg->{status} ? $arg->{status}->as_string : 'never ran'),
    },
  );

  my $subject = sprintf '%s%s', ($arg->{is_fail} ? 'FAIL: ' : ''), $subject;

  my $irt = sprintf '<%s@%s>', md5_hex($subject), $host;

  my $email = Email::Simple->create(
    body   => $body,
    header => [
      To      => join(', ', @$rcpts),
      From    => qq{"cron/$host" <$sender>},
      Subject => $subject,
      'In-Reply-To' => $irt,
      'Auto-Submitted' => 'auto-generated',
      @{ $arg->{extra_headers} },
    ],
  );

  Email::Sender::Simple->send(
    $email,
    {
      to      => $rcpts,
      from    => $sender,
    }
  );
}

BEGIN {
$TEMPLATE = <<'END_TEMPLATE'
Command: { $command }
Time   : { $time }s
Status : { $status }

Output :

{ $output || '(no output)' }
END_TEMPLATE
}

{
  package App::Cronjob::Exception 1.200014;

  sub new {
    my ($class, $type, $text, $extra) = @_;
    bless { type => $type, text => $text, extra => $extra } => $class;
  }
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

App::Cronjob - wrap up programs to be run as cron jobs

=head1 VERSION

version 1.200014

=head1 PERL VERSION

This library should run on perls released even a long time ago.  It should
work on any version of perl released in the last five years.

Although it may work on older versions of perl, no guarantee is made that the
minimum required version will not be increased.  The version may be increased
for any reason, and there is no promise that patches will be accepted to
lower the minimum required perl.

=head1 SEE INSTEAD

This library, App::Cronjob, is not well documented.  Its internals may change
substantially until such point as it is documented.

Instead of using the library, you should run the program F<cronjob> that is
installed along with the library.

For a full description of the program's behavior, consult L<cronjob>.

=head1 AUTHOR

Ricardo Signes <cpan@semiotic.systems>

=head1 CONTRIBUTORS

=for stopwords chromatic Mark Jason Dominus Ricardo Signes Rob N ★

=over 4

=item *

chromatic <chromatic@wgz.org>

=item *

Mark Jason Dominus <mjd@plover.com>

=item *

Ricardo Signes <rjbs@semiotic.systems>

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.952 second using v1.00-cache-2.02-grep-82fe00e-cpan-dad7e4baca0 )