diff options
| author | fukachan <fukachan> | 2001-03-20 09:44:57 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2001-03-20 09:44:57 +0000 |
| commit | db1c5797b32dd075bcf455c5300ed82f9b22b8aa (patch) | |
| tree | cd9c9f2524dcf5a063f1345b53e8681451ab6d51 /fml | |
| parent | 2198c4ce73b096d94ac6cbc591c86eca0a73b054 (diff) | |
| download | fml8-db1c5797b32dd075bcf455c5300ed82f9b22b8aa.tar.gz fml8-db1c5797b32dd075bcf455c5300ed82f9b22b8aa.tar.bz2 fml8-db1c5797b32dd075bcf455c5300ed82f9b22b8aa.zip | |
rewritten to ErrorMessages::Status module for unification of error
buffer handling.
Diffstat (limited to 'fml')
| -rw-r--r-- | fml/lib/ErrorMessages/Status.pm (renamed from fml/lib/File/Errors.pm) | 21 | ||||
| -rw-r--r-- | fml/lib/FML/Config.pm | 17 | ||||
| -rw-r--r-- | fml/lib/FML/Errors.pm | 73 | ||||
| -rw-r--r-- | fml/lib/FML/Ticket/System.pm | 6 | ||||
| -rw-r--r-- | fml/lib/File/Sequence.pm | 6 | ||||
| -rw-r--r-- | fml/lib/File/SimpleLock.pm | 12 | ||||
| -rw-r--r-- | fml/lib/IO/Adapter/Array.pm | 3 | ||||
| -rw-r--r-- | fml/lib/IO/Adapter/DBI.pm | 27 | ||||
| -rw-r--r-- | fml/lib/IO/Adapter/File.pm | 9 | ||||
| -rw-r--r-- | fml/lib/IO/Adapter/MySQL.pm | 4 | ||||
| -rw-r--r-- | fml/lib/IO/MapAdapter.pm | 36 | ||||
| -rw-r--r-- | fml/lib/MailingList/Net/INET4.pm | 4 | ||||
| -rw-r--r-- | fml/lib/MailingList/SMTP.pm | 4 | ||||
| -rw-r--r-- | fml/lib/MailingList/Utils.pm | 39 |
14 files changed, 53 insertions, 208 deletions
diff --git a/fml/lib/File/Errors.pm b/fml/lib/ErrorMessages/Status.pm index 2980fd0c..ea96a48d 100644 --- a/fml/lib/File/Errors.pm +++ b/fml/lib/ErrorMessages/Status.pm @@ -8,30 +8,31 @@ # $FML$ # -package File::Errors; +package ErrorMessages::Status; + use strict; use vars qw(@ISA @EXPORT @EXPORT_OK); use Carp; require Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(error_reason error error_reset); +@EXPORT_OK = qw(error_set error error_reset); =head1 NAME -File::Errors - error handling utilities +ErrorMessages::Status - error handling component =head1 SYNOPSIS -Consider C<Something> class module +Use this module in your C<Something> class module like this: package Something; - use File::Errors qw(error_reason error error_reset); + use ErrorMessages::Status qw(error_set error error_reset); sub xxx { if something errors ... - $self->error_reason( error reason ); + $self->error_set( why this error occurs ... ); } You use C<Something> module like this. @@ -47,18 +48,18 @@ simple utility functions to manipulate error messages. =head1 METHODS -=head2 C<error_reason($message)> +=head2 C<error_set($message)> save $message as an error message. =head2 C<error()> -return $message which is saved by C<error_reason($msg)>. +return $message which is saved by C<error_set($msg)>. =cut -sub error_reason +sub error_set { my ($self, $mesg) = @_; $self->{'_error_reason'} = $mesg; @@ -95,7 +96,7 @@ redistribute it and/or modify it under the same terms as Perl itself. =head1 HISTORY -File::Errors appeared in fml5 mailing list driver package. +ErrorMessages::Status appeared in fml5 mailing list driver package. See C<http://www.fml.org/> for more details. =cut diff --git a/fml/lib/FML/Config.pm b/fml/lib/FML/Config.pm index 665e5eb1..8385b931 100644 --- a/fml/lib/FML/Config.pm +++ b/fml/lib/FML/Config.pm @@ -10,6 +10,7 @@ package FML::Config; use strict; use Carp; use vars qw(%_fml_config %_default_fml_config); +use ErrorMessages::Status qw(error_set error error_reset); =head1 NAME @@ -146,20 +147,6 @@ sub dump_variables } -sub _log -{ - my ($self, $msg) = @_; - $self->{ _error_message } = $msg; -} - - -sub error -{ - my ($self) = @_; - $self->{ _error_message }; -} - - sub get { my ($self, $key) = @_; @@ -216,7 +203,7 @@ sub load_file $fh->close; } else { - $self->_log("Error: cannot open $file"); + $self->error_set("Error: cannot open $file"); } # first time diff --git a/fml/lib/FML/Errors.pm b/fml/lib/FML/Errors.pm deleted file mode 100644 index f19b231c..00000000 --- a/fml/lib/FML/Errors.pm +++ /dev/null @@ -1,73 +0,0 @@ -#-*- perl -*- -# -# Copyright (C) 2001 Ken'ichi Fukamachi -# All rights reserved. This program is free software; you can -# redistribute it and/or modify it under the same terms as Perl itself. -# -# $Id$ -# $FML$ -# - -package FML::Errors; -use strict; -use vars qw(@ISA @EXPORT @EXPORT_OK); -use Carp; - -use File::Errors qw(error_reason error error_reset); - -require Exporter; -@ISA = qw(File::Errors Exporter); -@EXPORT_OK = qw(error_reason error error_reset); - -=head1 NAME - -FML::Errors - error handling utilities - -=head1 SYNOPSIS - -Consider the following C<Something> module. - - package Something; - use FML::Errors qw(error_reason error error_reset); - - sub xxx - { - if something errors ... - $self->error_reason( error reason ); - } - -When you use C<Something> module, - - use Something; - $obj = new Something; - unless ($obj->error) { $obj->do_somting( ...); }; - -=head1 DESCRIPTION - -This is a wrapper to L<File::Errors>. -All requests are forwarded to C<File::Errors>. - -=head1 SEE ALSO - -L<File::Errors> - -=head1 AUTHOR - -Ken'ichi Fukamachi - -=head1 COPYRIGHT - -Copyright (C) 2001 Ken'ichi Fukamachi - -All rights reserved. This program is free software; you can -redistribute it and/or modify it under the same terms as Perl itself. - -=head1 HISTORY - -FML::Errors appeared in fml5 mailing list driver package. -See C<http://www.fml.org/> for more details. - -=cut - - -1; diff --git a/fml/lib/FML/Ticket/System.pm b/fml/lib/FML/Ticket/System.pm index 6da78704..045feb9d 100644 --- a/fml/lib/FML/Ticket/System.pm +++ b/fml/lib/FML/Ticket/System.pm @@ -13,7 +13,7 @@ package FML::Ticket::System; use strict; use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD); use Carp; -use FML::Errors qw(error_reason error error_reset); +use ErrorMessages::Status qw(error_set error error_reset); use FML::Log qw(Log LogWarn LogError); @@ -104,7 +104,7 @@ sub _init_ticket_db_dir unless (-d $db_dir) { use File::Utils qw(mkdirhier); mkdirhier($db_dir, $config->{ default_directory_mode }) || do { - $self->error_reason( File::Utils->error() ); + $self->error_set( File::Utils->error() ); return undef; }; } @@ -169,7 +169,7 @@ sub increment_id use File::Sequence; my $sfh = new File::Sequence { sequence_file => $seq_file }; my $id = $sfh->increment_id; - $self->error_reason( $sfh->error ); + $self->error_set( $sfh->error ); $id; } diff --git a/fml/lib/File/Sequence.pm b/fml/lib/File/Sequence.pm index 5cfc90e6..d770fa5f 100644 --- a/fml/lib/File/Sequence.pm +++ b/fml/lib/File/Sequence.pm @@ -12,7 +12,7 @@ package File::Sequence; use strict; use vars qw(@ISA @EXPORT @EXPORT_OK); use Carp; -use File::Errors qw(error_reason error error_reset); +use ErrorMessages::Status qw(error_set error error_reset); =head1 NAME @@ -96,7 +96,7 @@ sub increment_id my $seq_file = $file || $self->{ _sequence_file }; unless ($seq_file) { - $self->error_reason("the sequence file is not specified"); + $self->error_set("the sequence file is not specified"); return 0; }; @@ -115,7 +115,7 @@ sub increment_id $rh->close; } else { - $self->error_reason("cannot open the sequence file"); + $self->error_set("cannot open the sequence file"); return 0; } diff --git a/fml/lib/File/SimpleLock.pm b/fml/lib/File/SimpleLock.pm index ab789d77..3245e81b 100644 --- a/fml/lib/File/SimpleLock.pm +++ b/fml/lib/File/SimpleLock.pm @@ -11,9 +11,7 @@ package File::SimpleLock; use vars qw(%LockedFileHandle %FileIsLocked @ISA $Error); use strict; use Carp; -use File::Errors; - -@ISA = qw(File::Errors); +use ErrorMessages::Status qw(error_set error error_reset); =head1 NAME @@ -96,7 +94,7 @@ sub _simple_flock eval q{ $r = flock($fh, &LOCK_EX); }; - $self->error_reason($@) if $@; + $self->error_set($@) if $@; if ($r) { $FileIsLocked{ $file } = 1; @@ -104,7 +102,7 @@ sub _simple_flock } } else { - $self->error_reason("cannot open $file"); + $self->error_set("cannot open $file"); } return 0; @@ -124,7 +122,7 @@ sub _simple_funlock eval q{ $r = flock($fh, &LOCK_UN); }; - $self->error_reason($@) if $@; + $self->error_set($@) if $@; if ($r) { delete $FileIsLocked{ $file }; @@ -139,7 +137,7 @@ sub _simple_funlock =head1 SEE ALSO L<FileHandle>, -L<File::Errors>, +L<ErrorMessages::Status>, =head1 AUTHOR diff --git a/fml/lib/IO/Adapter/Array.pm b/fml/lib/IO/Adapter/Array.pm index acc60775..04b6970d 100644 --- a/fml/lib/IO/Adapter/Array.pm +++ b/fml/lib/IO/Adapter/Array.pm @@ -13,6 +13,7 @@ package IO::Adapter::Array; use strict; use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD); use Carp; +use ErrorMessages::Status qw(error_set error error_reset); =head1 NAME @@ -84,7 +85,7 @@ sub open my $r_array = $self->{ _array_reference}; if ($flag ne 'r') { - $self->_error_reason("Error: type=$self->{_type} is read only."); + $self->error_set("Error: type=$self->{_type} is read only."); return undef; } diff --git a/fml/lib/IO/Adapter/DBI.pm b/fml/lib/IO/Adapter/DBI.pm index 527e9529..50f5e2b8 100644 --- a/fml/lib/IO/Adapter/DBI.pm +++ b/fml/lib/IO/Adapter/DBI.pm @@ -11,6 +11,7 @@ package IO::Adapter::DBI; use strict; use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD); use Carp; +use ErrorMessages::Status qw(error_set error error_reset); =head1 NAME @@ -69,12 +70,12 @@ sub execute return $res; } else { - $self->error_reason( $DBI::errstr ); + $self->error_set( $DBI::errstr ); return undef; } } else { - $self->error_reason( $DBI::errstr ); + $self->error_set( $DBI::errstr ); return undef; } } @@ -105,7 +106,7 @@ sub open # try to connect my $dbh = DBI->connect($dsn, $user, $password); unless (defined $dbh) { - $self->error_reason( $DBI::errstr ); + $self->error_set( $DBI::errstr ); return undef; } @@ -130,24 +131,4 @@ sub close } -=head2 C<error_reason($mesg)> - -=head2 C<error()> - -=cut - -sub error_reason -{ - my ($self, $mesg) = @_; - $self->{ _error } = $mesg; -} - - -sub error -{ - my ($self) = @_; - return $self->{ _error }; -} - - 1; diff --git a/fml/lib/IO/Adapter/File.pm b/fml/lib/IO/Adapter/File.pm index b0378933..cd647134 100644 --- a/fml/lib/IO/Adapter/File.pm +++ b/fml/lib/IO/Adapter/File.pm @@ -13,6 +13,7 @@ package IO::Adapter::File; use strict; use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD); use Carp; +use ErrorMessages::Status qw(error_set error error_reset); =head1 NAME @@ -106,7 +107,7 @@ sub _read_open return $fh; } else { - $self->_error_reason("Error: cannot open file=$file flag=$flag"); + $self->error_set("Error: cannot open file=$file flag=$flag"); return undef; } } @@ -261,7 +262,7 @@ sub add $fh->close; } else { - $self->_error_reason("Error: cannot open file=$self->{ _file }"); + $self->error_set("Error: cannot open file=$self->{ _file }"); return undef; } @@ -295,7 +296,7 @@ sub delete $wh->close; } else { - $self->_error_reason("Error: cannot open file=$self->{ _file }"); + $self->error_set("Error: cannot open file=$self->{ _file }"); return undef; } } @@ -330,7 +331,7 @@ sub replace $wh->close; } else { - $self->_error_reason("Error: cannot open file=$self->{ _file }"); + $self->error_set("Error: cannot open file=$self->{ _file }"); return undef; } } diff --git a/fml/lib/IO/Adapter/MySQL.pm b/fml/lib/IO/Adapter/MySQL.pm index 28a93433..cbc97a96 100644 --- a/fml/lib/IO/Adapter/MySQL.pm +++ b/fml/lib/IO/Adapter/MySQL.pm @@ -94,7 +94,7 @@ sub configure $me->{ _schema } = $pkg; } else { - error_reason($self, $@); + error_set($self, $@); return undef; } } @@ -140,7 +140,7 @@ sub get_next_value join(" ", @row); } else { - $self->error_reason( $DBI::errstr ); + $self->error_set( $DBI::errstr ); undef; } } diff --git a/fml/lib/IO/MapAdapter.pm b/fml/lib/IO/MapAdapter.pm index 1688b910..7f8d5e36 100644 --- a/fml/lib/IO/MapAdapter.pm +++ b/fml/lib/IO/MapAdapter.pm @@ -12,6 +12,7 @@ package IO::MapAdapter; use vars qw(@ISA @ORIG_ISA $FirstTime); use strict; use Carp; +use ErrorMessages::Status qw(error_set error error_reset); BEGIN {} END {} @@ -150,7 +151,7 @@ sub new } else { my $s = "IO::MapAdapter::new: map='$map' is unknown."; - _error_reason($me, $s); + error_set($me, $s); } } @@ -160,7 +161,7 @@ sub new eval qq{ require $pkg; $pkg->import();}; $pkg->configure($me, $args) if $pkg->can('configure'); - _error_reason($me, $@) if $@; + error_set($me, $@) if $@; return bless $me, $type; } @@ -201,7 +202,7 @@ sub open $self->SUPER::open( { flag => $flag } ); } else { - $self->_error_reason("Error: type=$self->{_type} is unknown type."); + $self->error_set("Error: type=$self->{_type} is unknown type."); } } @@ -272,7 +273,7 @@ sub add $self->SUPER::add($address); } else { - $self->_error_reason("Error: add() method is not supported."); + $self->error_set("Error: add() method is not supported."); undef; } } @@ -290,7 +291,7 @@ sub delete $self->SUPER::delete($regexp); } else { - $self->_error_reason("Error: delete() method is not supported."); + $self->error_set("Error: delete() method is not supported."); undef; } } @@ -308,7 +309,7 @@ sub replace $self->SUPER::replace($regexp, $value); } else { - $self->_error_reason("Error: replace() method is not supported."); + $self->error_set("Error: replace() method is not supported."); undef; } } @@ -327,29 +328,6 @@ sub DESTROY } -# Descriptions: log the error message in the object -# internal use fucntion. -# Arguments: $self $mesg -# $mesg is the error message string. -# Side Effects: $self->{ _error_reason } is set to $mesg. -# Return Value: $mesg -sub _error_reason -{ - my ($self, $mesg) = @_; - $self->{ _error_reason } = $mesg; -} - - -# Descriptions: return the error message -# Arguments: $self -# Side Effects: none -# Return Value: error message -sub error -{ - my ($self) = @_; - return $self->{ _error_reason }; -} - =head2 =item C<error()> diff --git a/fml/lib/MailingList/Net/INET4.pm b/fml/lib/MailingList/Net/INET4.pm index 411984e2..f2ebfe78 100644 --- a/fml/lib/MailingList/Net/INET4.pm +++ b/fml/lib/MailingList/Net/INET4.pm @@ -33,7 +33,7 @@ sub connect4 }; if ($@) { Log("Error: cannot make socket for $mta"); - $self->_error_reason("Error: cannot make socket: $@"); + $self->error_set("Error: cannot make socket: $@"); return undef; } @@ -45,7 +45,7 @@ sub connect4 } else { Log("(debug) error. fail to connect $mta"); - $self->_error_reason("Error: cannot open socket: $!"); + $self->error_set("Error: cannot open socket: $!"); return undef; } } diff --git a/fml/lib/MailingList/SMTP.pm b/fml/lib/MailingList/SMTP.pm index 4eefec76..fbde8421 100644 --- a/fml/lib/MailingList/SMTP.pm +++ b/fml/lib/MailingList/SMTP.pm @@ -227,7 +227,7 @@ sub _read_reply if ($@ =~ /$id socket timeout/) { my $x = $self->{'_last_command'}; Log("Error: smtp reply for \"$x\" is timeout"); - $self->_error_reason("Error: smtp reply for \"$x\" is timeout"); + $self->error_set("Error: smtp reply for \"$x\" is timeout"); } # reset latest alarm() setting @@ -613,7 +613,7 @@ sub _send_recipient_list_by_recipient_map my $recipient_limit = $self->{_recipient_limit}; $obj->open || do { - $self->_error_reason( $obj->error ); + $self->error_set( $obj->error ); return undef; }; diff --git a/fml/lib/MailingList/Utils.pm b/fml/lib/MailingList/Utils.pm index 3db39fc9..7c6004e9 100644 --- a/fml/lib/MailingList/Utils.pm +++ b/fml/lib/MailingList/Utils.pm @@ -13,6 +13,7 @@ use strict; use vars qw(@ISA @EXPORT @EXPORT_OK $LogFunctionPointer $SmtpLogFunctionPointer); use Carp; +use ErrorMessages::Status qw(error_set error error_reset); require Exporter; @ISA = qw(Exporter); @@ -25,7 +26,7 @@ require Exporter; $LogFunctionPointer $SmtpLogFunctionPointer - _error_reason + error_set error error_reset @@ -140,50 +141,20 @@ sub _smtplog =head1 METHODS FOR ERROR MESSAGES AND STATUS CODES -=head2 C<error_reason($mesg)> +=head2 C<error_set($mesg)> save C<$mesg>. =head2 C<error()> -return the latest error message which saved by C<error_reason()>. +return the latest error message which saved by C<error_set()>. =head2 C<error_reset()> -reset the error buffer which C<error_reason()> and C<error()> use. +reset the error buffer which C<error_set()> and C<error()> use. =cut -sub _error_reason -{ - my ($self, $mesg) = @_; - $self->{'_error_reason'} = $mesg; -} - - -sub error_reason -{ - my ($self, $mesg) = @_; - $self->_error_reason($mesg); -} - - -sub error -{ - my ($self, $args) = @_; - return $self->{'_error_reason'}; -} - - -sub error_reset -{ - my ($self, $args) = @_; - my $msg = $self->{'_error_reason'}; - undef $self->{'_error_reason'} if defined $self->{'_error_reason'}; - undef $self->{'_error_action'} if defined $self->{'_error_action'}; - return $msg; -} - ################################################################# ##### |
