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 / MIMELite.pm < prev    next >
Encoding:
Perl POD Document  |  2003-09-27  |  3.1 KB  |  136 lines

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