| 1 | # | ||||||||||||
| 2 | # Mail/Salsa/Logs.pm | ||||||||||||
| 3 | # Last Modification: Wed Apr 6 16:13:12 WEST 2005 | ||||||||||||
| 4 | # | ||||||||||||
| 5 | # Copyright (c) 2005 Henrique Dias <hdias@aesbuc.pt>. All rights reserved. | ||||||||||||
| 6 | # This module is free software; you can redistribute it and/or modify | ||||||||||||
| 7 | # it under the same terms as Perl itself. | ||||||||||||
| 8 | # | ||||||||||||
| 9 | package Mail::Salsa::Logs; | ||||||||||||
| 10 | |||||||||||||
| 11 | 10 | ▶ | use 5.008000; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 10 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 10 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | |||||||||||||
| 15 | 10 | require Exporter; | |||||||||||
| 16 | 10 | ▶ | use AutoLoader qw(AUTOLOAD); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 10 | ▶ | use Mail::Salsa::Utils; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | |||||||||||||
| 19 | 10 | our @ISA = qw(Exporter); | |||||||||||
| 20 | |||||||||||||
| 21 | # Items to export into callers namespace by default. Note: do not export | ||||||||||||
| 22 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||||
| 23 | # Do not simply export all your public functions/methods/constants. | ||||||||||||
| 24 | |||||||||||||
| 25 | # This allows declaration use Mail::Salsa::Logs ':all'; | ||||||||||||
| 26 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | ||||||||||||
| 27 | # will save memory. | ||||||||||||
| 28 | 10 | our %EXPORT_TAGS = ( 'all' => [ qw() ] ); | |||||||||||
| 29 | |||||||||||||
| 30 | 10 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||
| 31 | |||||||||||||
| 32 | 10 | our @EXPORT = qw(&logs &debug); | |||||||||||
| 33 | |||||||||||||
| 34 | 10 | our $VERSION = '0.02'; | |||||||||||
| 35 | |||||||||||||
| 36 | 0 | ▶ | sub logs { | ||||||||||
|
Subroutine
logs: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||
| 37 | 0 | my $self = shift; | |||||||||||
| 38 | 0 | my $string = shift; | |||||||||||
| 39 | 0 | ▶ | my $type = shift || "error"; | ||||||||||
|
Condition0%0/2
shift() || 'error'
MC/DC0%0/1
shift() || 'error'
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 40 | |||||||||||||
| 41 | 0 | my ($name, $domain) = split(/\@/, $self->{'list'}); | |||||||||||
| 42 | 0 | my $dir = join("/", $self->{'logs_dir'}, $domain, $name); | |||||||||||
| 43 | 0 | ▶ | unless(-d $dir) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 44 | 0 | Mail::Salsa::Utils::make_dir_rec($dir, 0755); | |||||||||||
| 45 | 0 | ▶ | (-d $dir) or die("$!"); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | } | ||||||||||||
| 47 | 0 | my $today = Mail::Salsa::Utils::string_date(); | |||||||||||
| 48 | 0 | ▶ | $string .= "\n" unless($string =~ /\n+$/); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 49 | 0 | ▶ | if($string eq "error") { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 50 | 0 | my $package = caller(); | |||||||||||
| 51 | 0 | $string = "$package $string"; | |||||||||||
| 52 | } | ||||||||||||
| 53 | 0 | my $file = join("/", $dir, "$type\.log"); | |||||||||||
| 54 | 0 | ▶ | open(LOGS, ">>", $file) or die("$!"); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 55 | 0 | print LOGS "$today $string"; | |||||||||||
| 56 | 0 | close(LOGS); | |||||||||||
| 57 | |||||||||||||
| 58 | 0 | my $mode = 0600; | |||||||||||
| 59 | 0 | chmod($mode, $file); | |||||||||||
| 60 | |||||||||||||
| 61 | 0 | return(); | |||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | 0 | ▶ | sub debug { | ||||||||||
|
Subroutine
debug: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||
| 65 | 0 | my $self = shift; | |||||||||||
| 66 | 0 | my $string = shift; | |||||||||||
| 67 | |||||||||||||
| 68 | 0 | ▶ | $string .= "\n" unless($string =~ /\n+$/); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 69 | 0 | ▶ | open(DEBUG, ">>", "/tmp/salsa.debug") or die("$!"); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 70 | 0 | print DEBUG $string; | |||||||||||
| 71 | 0 | close(DEBUG); | |||||||||||
| 72 | |||||||||||||
| 73 | 0 | return(); | |||||||||||
| 74 | } | ||||||||||||
| 75 | |||||||||||||
| 76 | # Preloaded methods go here. | ||||||||||||
| 77 | |||||||||||||
| 78 | # Autoload methods go after =cut, and are processed by the autosplit program. | ||||||||||||
| 79 | |||||||||||||
| 80 | 10 | 1; | |||||||||||
| 81 | __END__ | ||||||||||||