diff options
| author | fukachan <fukachan> | 2004-07-11 15:25:51 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2004-07-11 15:25:51 +0000 |
| commit | beb5a1d8ec3c57d3879d39435f726ad73e67e72f (patch) | |
| tree | b8c3a91c288916569e1dba154a738c09bacf890a /fml/lib/IO | |
| parent | 44b291438d5f255aef4af6a30d7f1e8efd26a0b3 (diff) | |
| download | fml8-beb5a1d8ec3c57d3879d39435f726ad73e67e72f.tar.gz fml8-beb5a1d8ec3c57d3879d39435f726ad73e67e72f.tar.bz2 fml8-beb5a1d8ec3c57d3879d39435f726ad73e67e72f.zip | |
fix comments.
explicitly use "return".
modify error messages.
ensure initialized value.
Diffstat (limited to 'fml/lib/IO')
| -rw-r--r-- | fml/lib/IO/Adapter.pm | 3 | ||||
| -rw-r--r-- | fml/lib/IO/Adapter/AtomicFile.pm | 6 | ||||
| -rw-r--r-- | fml/lib/IO/Adapter/DBI.pm | 10 | ||||
| -rw-r--r-- | fml/lib/IO/Adapter/File.pm | 42 | ||||
| -rw-r--r-- | fml/lib/IO/Adapter/MySQL.pm | 5 |
5 files changed, 38 insertions, 28 deletions
diff --git a/fml/lib/IO/Adapter.pm b/fml/lib/IO/Adapter.pm index d44151ba..222da945 100644 --- a/fml/lib/IO/Adapter.pm +++ b/fml/lib/IO/Adapter.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: Adapter.pm,v 1.33 2004/04/27 13:31:54 fukachan Exp $ +# $FML: Adapter.pm,v 1.34 2004/06/30 03:05:14 fukachan Exp $ # package IO::Adapter; @@ -494,6 +494,7 @@ sub find $self->close; + # XXX-TODO: $x = "STR STR STR" ? should be $x => [] ? $show_all ? \@buf : $x; } diff --git a/fml/lib/IO/Adapter/AtomicFile.pm b/fml/lib/IO/Adapter/AtomicFile.pm index b2dfeed7..9378fd8c 100644 --- a/fml/lib/IO/Adapter/AtomicFile.pm +++ b/fml/lib/IO/Adapter/AtomicFile.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: AtomicFile.pm,v 1.12 2004/05/25 04:03:49 fukachan Exp $ +# $FML: AtomicFile.pm,v 1.13 2004/06/27 05:51:22 fukachan Exp $ # package IO::Adapter::AtomicFile; @@ -19,7 +19,7 @@ END {} =head1 NAME -IO::Adapter::AtomicFile - atomic IO operation +IO::Adapter::AtomicFile - atomic IO operation. =head1 SYNOPSIS @@ -41,7 +41,7 @@ In usual cases, you use this module in the following way. # get read handle for $file my $rh = new FileHandle $file; - # get handle to update $file + # get handle to update $file my $wh = IO::Adapter::AtomicFile->open($file); if (defined $rh && defined $wh) { while (<$rh>) { diff --git a/fml/lib/IO/Adapter/DBI.pm b/fml/lib/IO/Adapter/DBI.pm index a8940531..e801c478 100644 --- a/fml/lib/IO/Adapter/DBI.pm +++ b/fml/lib/IO/Adapter/DBI.pm @@ -3,7 +3,7 @@ # Copyright (C) 2000,2001,2002,2003,2004 Ken'ichi Fukamachi # All rights reserved. # -# $FML: DBI.pm,v 1.29 2003/11/26 11:00:32 fukachan Exp $ +# $FML: DBI.pm,v 1.30 2004/01/24 09:03:55 fukachan Exp $ # package IO::Adapter::DBI; @@ -18,7 +18,7 @@ my $debug = 0; =head1 NAME -IO::Adapter::DBI - DBI abstraction layer +IO::Adapter::DBI - DBI abstraction layer. =head1 SYNOPSIS @@ -212,7 +212,7 @@ sub get_next_key } -# Descriptions: get from DBI map. +# Descriptions: get data from cache obtained from DBI. # Arguments: OBJ($self) HASH_REF($args) STR($mode) # Side Effects: none # Return Value: STR @@ -253,11 +253,12 @@ sub _get_data_from_cache } else { warn("DBI: invalid option"); + return undef; } } else { $self->error_set( $DBI::errstr ); - undef; + return undef; } } @@ -386,6 +387,7 @@ sub md_find $self->close(); + # XXX-TODO: $x = "STR STR STR" ? should be $x => [] ? return( $show_all ? \@buf : $x ); } diff --git a/fml/lib/IO/Adapter/File.pm b/fml/lib/IO/Adapter/File.pm index 785bdcb5..da2bf7c1 100644 --- a/fml/lib/IO/Adapter/File.pm +++ b/fml/lib/IO/Adapter/File.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: File.pm,v 1.56 2004/05/25 04:03:06 fukachan Exp $ +# $FML: File.pm,v 1.57 2004/06/27 05:59:10 fukachan Exp $ # package IO::Adapter::File; @@ -21,7 +21,7 @@ my $debug = 0; =head1 NAME -IO::Adapter::File - IO functions for a file +IO::Adapter::File - IO functions for a file. =head1 SYNOPSIS @@ -56,12 +56,12 @@ prefix. =head2 new() -standard constructor. +constructor. =cut -# Descriptions: standard constructor. +# Descriptions: constructor. # Arguments: OBJ($self) # Side Effects: none # Return Value: OBJ @@ -119,7 +119,7 @@ sub _read_open return $fh; } else { - $self->error_set("Error: cannot open file=$file flag=$flag"); + $self->error_set("cannot open file=$file flag=$flag"); return undef; } } @@ -139,7 +139,8 @@ sub _rw_open my ($rh, $wh) = IO::Adapter::AtomicFile->rw_open($file); $self->{ _fh } = $rh; $self->{ _wh } = $wh; - $rh; + + return $rh; } @@ -260,16 +261,16 @@ sub _get_next_xxx $buf =~ s/[\r\n]*$//o; my ($key, $value) = split(/\s+/, $buf, 2); if ($mode eq 'key') { - $buf = $key; + $buf = $key || ''; } elsif ($mode eq 'value_as_str') { - $buf = $value; + $buf = $value || ''; } elsif ($mode eq 'value_as_array_ref') { $value =~ s/^\s*//; $value =~ s/\s*$//; (@buf) = split(/\s+/, $value); - $buf = \@buf; + $buf = \@buf || []; } elsif ($mode eq 'key,value_as_array_ref') { @buf = (); # reset; @@ -281,7 +282,7 @@ sub _get_next_xxx (@buf) = split(/\s+/, $value); } unshift(@buf, $key); - $buf = \@buf; + $buf = \@buf || []; } else { $buf = []; @@ -384,6 +385,7 @@ sub add { my ($self, $addr, $argv) = @_; + # XXX-TODO: open only if not opened ? $self->open("w"); my $fh = $self->{ _fh }; @@ -408,7 +410,7 @@ sub add print $wh $addr, "\t", $argv, "\n"; } else { - $self->error_set("Error: add: invalid args"); + $self->error_set("add: invalid args"); $wh->close; return undef; } @@ -420,7 +422,7 @@ sub add $wh->close; } else { - $self->error_set("Error: cannot open file=$self->{ _file }"); + $self->error_set("cannot open file=$self->{ _file }"); return undef; } } @@ -433,7 +435,7 @@ delete lines with key $key from this map. =cut -# Descriptions: delete address(es) matching $reexp from map. +# Descriptions: delete address(es) matching $regexp from map. # Arguments: OBJ($self) STR($key) # Side Effects: update map # Return Value: same as close() @@ -442,6 +444,7 @@ sub delete my ($self, $key) = @_; my $found = 0; + # XXX-TODO: open only if not opened ? $self->open("w"); my $fh = $self->{ _fh }; @@ -464,11 +467,11 @@ sub delete $fh->close; unless ($found) { - $self->error_set("Error: not match"); + $self->error_set("not match"); } } else { - $self->error_set("Error: cannot open file=$self->{ _file }"); + $self->error_set("cannot open file=$self->{ _file }"); return undef; } } @@ -496,7 +499,7 @@ sub lock } -# Descriptions: un-flock file (create a file if needed). +# Descriptions: un-flock file. # Arguments: OBJ($self) HASH_REF($args) # Side Effects: none # Return Value: none @@ -549,7 +552,7 @@ sub _simple_flock # Descriptions: try unlock by flock(2) for $file. # Arguments: OBJ($self) STR($file) # Side Effects: flock for $file -# Return Value: 1 or 0 +# Return Value: NUM( 1 or 0 ) sub _simple_funlock { my ($self, $file) = @_; @@ -631,9 +634,10 @@ For example, to set sequence number to the specified value $new_id: # Descriptions: increment value in the specified file. +# return new sequence number. # Arguments: OBJ($self) HASH_REF($args) # Side Effects: create a file if needed. -# Return Value: none +# Return Value: NUM sub sequence_increment { my ($self, $args) = @_; @@ -728,6 +732,7 @@ sub sequence_replace if ($wh->error()) { $self->error_set("write error"); $wh->rollback(); + return 0; } else { $wh->close; @@ -735,6 +740,7 @@ sub sequence_replace } else { $self->error_set("cannot save id"); + return 0; } # verify if the value is writtern. diff --git a/fml/lib/IO/Adapter/MySQL.pm b/fml/lib/IO/Adapter/MySQL.pm index f5bd1c03..263bb86e 100644 --- a/fml/lib/IO/Adapter/MySQL.pm +++ b/fml/lib/IO/Adapter/MySQL.pm @@ -3,7 +3,7 @@ # Copyright (C) 2000,2001,2002,2003,2004 Ken'ichi Fukamachi # All rights reserved. # -# $FML: MySQL.pm,v 1.26 2003/08/23 04:35:44 fukachan Exp $ +# $FML: MySQL.pm,v 1.27 2004/01/24 09:03:56 fukachan Exp $ # @@ -21,7 +21,7 @@ push(@ISA, 'IO::Adapter::DBI'); =head1 NAME -IO::Adapter::MySQL - interface to talk with a MySQL server +IO::Adapter::MySQL - interface to talk with a MySQL server. =head1 SYNOPSIS @@ -170,6 +170,7 @@ sub eof { my ($self) = @_; + # XXX-TODO: correct ? return( $self->{ _row_pos } < $self->{ _row_max } ? 0 : 1 ); } |
