home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / MailSendmail.pm < prev    next >
Encoding:
Perl POD Document  |  2003-09-27  |  3.3 KB  |  138 lines

  1. package Log::Dispatch::Email::MailSendmail;
  2.  
  3. use strict;
  4.  
  5. use Log::Dispatch::Email;
  6.  
  7. use base qw( Log::Dispatch::Email );
  8.  
  9. use Mail::Sendmail ();
  10.  
  11. use vars qw[ $VERSION ];
  12.  
  13. $VERSION = sprintf "%d.%02d", q$Revision: 1.20 $ =~ /: (\d+)\.(\d+)/;
  14.  
  15. 1;
  16.  
  17. sub send_email
  18. {
  19.     my $self = shift;
  20.     my %p = @_;
  21.  
  22.     my %mail = ( To      => (join ',', @{ $self->{to} }),
  23.          Subject => $self->{subject},
  24.          Message => $p{message},
  25.          # Mail::Sendmail insists on having this parameter.
  26.          From    => $self->{from} || 'LogDispatch@foo.bar',
  27.            );
  28.  
  29.     unless ( Mail::Sendmail::sendmail(%mail) )
  30.     {
  31.     warn "Error sending mail: $Mail::Sendmail::error" if $^W;
  32.     }
  33. }
  34.  
  35. __END__
  36.  
  37. =head1 NAME
  38.  
  39. Log::Dispatch::Email::MailSendmail - Subclass of Log::Dispatch::Email that uses the Mail::Sendmail module
  40.  
  41. =head1 SYNOPSIS
  42.  
  43.   use Log::Dispatch::Email::MailSendmail;
  44.  
  45.   my $email =
  46.       Log::Dispatch::Email::MailSendmail->new
  47.           ( name => 'email',
  48.             min_level => 'emerg',
  49.             to => [ qw( foo@bar.com bar@baz.org ) ],
  50.             subject => 'Oh no!!!!!!!!!!!', );
  51.  
  52.   $email->log( message => 'Something bad is happening', level => 'emerg' );
  53.  
  54. =head1 DESCRIPTION
  55.  
  56. This is a subclass of Log::Dispatch::Email that implements the
  57. send_email method using the Mail::Sendmail module.
  58.  
  59. =head1 METHODS
  60.  
  61. =over 4
  62.  
  63. =item * new
  64.  
  65. This method takes a hash of parameters.  The following options are
  66. valid:
  67.  
  68. =over 8
  69.  
  70. =item * name ($)
  71.  
  72. The name of the object (not the filename!).  Required.
  73.  
  74. =item * min_level ($)
  75.  
  76. The minimum logging level this object will accept.  See the
  77. Log::Dispatch documentation for more information.  Required.
  78.  
  79. =item * max_level ($)
  80.  
  81. The maximum logging level this obejct will accept.  See the
  82. Log::Dispatch documentation for more information.  This is not
  83. required.  By default the maximum is the highest possible level (which
  84. means functionally that the object has no maximum).
  85.  
  86. =item * subject ($)
  87.  
  88. The subject of the email messages which are sent.  Defaults to "$0:
  89. log email"
  90.  
  91. =item * to ($ or \@)
  92.  
  93. Either a string or a list reference of strings containing email
  94. addresses.  Required.
  95.  
  96. =item * from ($)
  97.  
  98. A string containing an email address.  This is optional and may not
  99. work with all mail sending methods.
  100.  
  101. NOTE: The Mail::Sendmail module requires an address be passed to it to
  102. set this in the mail it sends.  We pass in 'LogDispatch@foo.bar' as
  103. the default.
  104.  
  105. =item * buffered (0 or 1)
  106.  
  107. This determines whether the object sends one email per message it is
  108. given or whether it stores them up and sends them all at once.  The
  109. default is to buffer messages.
  110.  
  111. =item * callbacks( \& or [ \&, \&, ... ] )
  112.  
  113. This parameter may be a single subroutine reference or an array
  114. reference of subroutine references.  These callbacks will be called in
  115. the order they are given and passed a hash containing the following keys:
  116.  
  117.  ( message => $log_message, level => $log_level )
  118.  
  119. The callbacks are expected to modify the message and then return a
  120. single scalar containing that modified message.  These callbacks will
  121. be called when either the C<log> or C<log_to> methods are called and
  122. will only be applied to a given message once.
  123.  
  124. =back
  125.  
  126. =item * log_message( level => $, message => $ )
  127.  
  128. Sends a message if the level is greater than or equal to the object's
  129. minimum level.
  130.  
  131. =back
  132.  
  133. =head1 AUTHOR
  134.  
  135. Dave Rolsky, <autarch@urth.org>
  136.  
  137. =cut
  138.