summaryrefslogtreecommitdiff
path: root/fml/lib/IO/Adapter
diff options
context:
space:
mode:
authorfukachan <fukachan>2002-01-27 13:11:57 +0000
committerfukachan <fukachan>2002-01-27 13:11:57 +0000
commitcd17f7899482fbcb118114a9b83cfb33db1520af (patch)
tree6d46915cd61bb3e763fc62c5c465fc31acbd4f9f /fml/lib/IO/Adapter
parent81cabe0bc65a6659185b73301b332653af03f67e (diff)
downloadfml8-cd17f7899482fbcb118114a9b83cfb33db1520af.tar.gz
fml8-cd17f7899482fbcb118114a9b83cfb33db1520af.tar.bz2
fml8-cd17f7899482fbcb118114a9b83cfb33db1520af.zip
clarify IO::Adapter definition and clean up get_XXX() functions.
remove get_member(), get_active() and get_recipient() define get_next_key() and get_next_value() and clarify thier definitions.
Diffstat (limited to 'fml/lib/IO/Adapter')
-rw-r--r--fml/lib/IO/Adapter/Array.pm37
-rw-r--r--fml/lib/IO/Adapter/DBI.pm41
-rw-r--r--fml/lib/IO/Adapter/File.pm42
-rw-r--r--fml/lib/IO/Adapter/IMPLEMENTATION.jp57
-rw-r--r--fml/lib/IO/Adapter/MySQL.pm8
5 files changed, 159 insertions, 26 deletions
diff --git a/fml/lib/IO/Adapter/Array.pm b/fml/lib/IO/Adapter/Array.pm
index 741850bb..52718957 100644
--- a/fml/lib/IO/Adapter/Array.pm
+++ b/fml/lib/IO/Adapter/Array.pm
@@ -1,10 +1,10 @@
#-*- perl -*-
#
-# Copyright (C) 2001 Ken'ichi Fukamachi
+# Copyright (C) 2001,2002 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.
#
-# $FML: Array.pm,v 1.20 2001/12/22 09:21:12 fukachan Exp $
+# $FML: Array.pm,v 1.21 2001/12/24 07:40:56 fukachan Exp $
#
package IO::Adapter::Array;
@@ -22,15 +22,22 @@ IO::Adapter::Array - base class for IO emulation for the ARRAY
use IO::Adapter::Array;
- $map = [ 1, 2, 3 ];
+ $map = [ 'rudo', 'kenken', 'hitomi' ];
$obj = new IO::Adapter::Array $map;
$obj->open;
- while ($x = $obj->get_next_value) { print $x;}
+ while ($x = $obj->get_next_key) { print $x;}
$obj->close;
=head1 DESCRIPTION
emulate IO operation for the ARRAY.
+One array is similar to a set of primary keys without optional values
+such as a file:
+
+ rudo
+ kenken
+ hitomi
+ ...
=head1 METHODS
@@ -103,25 +110,31 @@ sub open
the same as get_next_value().
-=item C<get_next_value()>
+=item C<get_next_key()>
return the next element of the array
+=item C<get_next_value()>
+
+undef. ambigous in array case.
+
=cut
-# Descriptions: forwarded to get_next_value()
+# Descriptions: forwarded to get_next_key()
+# XXX getline() == get_next_key() is valid in this case.
+# XXX since this map has only key and no value.
# Arguments: OBJ($self) HASH_REF($args)
# Side Effects: increment the counter in the object
# Return Value: STR(the next element)
-sub getline { get_next_value(@_);}
+sub getline { get_next_key(@_);}
# Descriptions: return the next element of the array
# Arguments: OBJ($self) HASH_REF($args)
# Side Effects: increment the counter in the object
# Return Value: STR(the next element)
-sub get_next_value
+sub get_next_key
{
my ($self, $args) = @_;
my $i = $self->{_counter}++;
@@ -130,6 +143,12 @@ sub get_next_value
}
+sub get_next_value
+{
+ return undef;
+}
+
+
=head2 C<getpos()>
return the current position in the array
@@ -203,7 +222,7 @@ Ken'ichi Fukamachi
=head1 COPYRIGHT
-Copyright (C) 2001 Ken'ichi Fukamachi
+Copyright (C) 2001,2002 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.
diff --git a/fml/lib/IO/Adapter/DBI.pm b/fml/lib/IO/Adapter/DBI.pm
index 9ba60351..9b789c34 100644
--- a/fml/lib/IO/Adapter/DBI.pm
+++ b/fml/lib/IO/Adapter/DBI.pm
@@ -3,7 +3,7 @@
# Copyright (C) 2000,2001,2002 Ken'ichi Fukamachi
# All rights reserved.
#
-# $FML: DBI.pm,v 1.11 2002/01/27 09:21:52 fukachan Exp $
+# $FML: DBI.pm,v 1.12 2002/01/27 09:25:24 fukachan Exp $
#
package IO::Adapter::DBI;
@@ -179,17 +179,39 @@ same as C<getline()> now.
sub getline
{
my ($self, $args) = @_;
- $self->get_next_value($args);
+ $self->get_next_key($args);
}
-# Descriptions: get from DBI map
-# Arguments: OBJ($self) HASH_REF($args)
+# Descriptions: return key from DBI map
+# Arguments: OBJ($self) HASH_REF($args) STR($mode)
+# Side Effects: none
+# Return Value: STR
+sub get_next_key
+{
+ my ($self, $args) = @_;
+ $self->_get_next_xxx($args, 'key');
+}
+
+
+# Descriptions: return value(s) from DBI map
+# Arguments: OBJ($self) HASH_REF($args) STR($mode)
# Side Effects: none
# Return Value: STR
sub get_next_value
{
my ($self, $args) = @_;
+ $self->_get_next_xxx($args, 'value');
+}
+
+
+# Descriptions: get from DBI map
+# Arguments: OBJ($self) HASH_REF($args) STR($mode)
+# Side Effects: none
+# Return Value: STR
+sub _get_next_xxx
+{
+ my ($self, $args, $mode) = @_;
# for the first time
unless ($self->{ _res }) {
@@ -213,7 +235,16 @@ sub get_next_value
my @row = $self->{ _res }->fetchrow_array;
$self->{ _row_pos }++;
- join(" ", @row);
+ if ($mode eq 'key') {
+ $row[0];
+ }
+ elsif ($mode eq 'value') {
+ shift @row;
+ join(" ", @row);
+ }
+ else {
+ warn("invalid option");
+ }
}
else {
$self->error_set( $DBI::errstr );
diff --git a/fml/lib/IO/Adapter/File.pm b/fml/lib/IO/Adapter/File.pm
index b125e68d..c9dc6f3c 100644
--- a/fml/lib/IO/Adapter/File.pm
+++ b/fml/lib/IO/Adapter/File.pm
@@ -1,10 +1,10 @@
#-*- perl -*-
#
-# Copyright (C) 2001 Ken'ichi Fukamachi
+# Copyright (C) 2001,2002 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.
#
-# $FML: File.pm,v 1.26 2001/12/24 07:40:56 fukachan Exp $
+# $FML: File.pm,v 1.27 2001/12/24 07:44:35 fukachan Exp $
#
package IO::Adapter::File;
@@ -192,14 +192,35 @@ sub getline
}
-# Descriptions: get string for new line after
-# clean up for fml
+# Descriptions: return the next key
+# Arguments: OBJ($self)
+# Side Effects: none
+# Return Value: STR
+sub get_next_key
+{
+ my ($self) = @_;
+ $self->_get_next_xxx('key');
+}
+
+
+# Descriptions: return value(s) for the next key
# Arguments: OBJ($self)
# Side Effects: none
# Return Value: STR
sub get_next_value
{
my ($self) = @_;
+ $self->_get_next_xxx('value');
+}
+
+
+# Descriptions: get data and return key or value by $mode.
+# Arguments: OBJ($self) STR($mode)
+# Side Effects: none
+# Return Value: STR
+sub _get_next_xxx
+{
+ my ($self, $mode) = @_;
my ($buf) = '';
my $fh = $self->{_fh};
@@ -218,9 +239,14 @@ sub get_next_value
}
if (defined $buf) {
- my @buf = split(/\s+/, $buf);
- $buf = $buf[0];
- $buf =~ s/[\r\n]*$//o;
+ $buf =~ s/[\r\n]*$//o;
+ my ($key, $value) = split(/\s+/, $buf, 2);
+ if ($mode eq 'key') {
+ $buf = $key;
+ }
+ elsif ($mode eq 'value') {
+ $buf = $value;
+ }
$ec++;
}
return $buf;
@@ -421,7 +447,7 @@ Ken'ichi Fukamachi
=head1 COPYRIGHT
-Copyright (C) 2001 Ken'ichi Fukamachi
+Copyright (C) 2001,2002 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.
diff --git a/fml/lib/IO/Adapter/IMPLEMENTATION.jp b/fml/lib/IO/Adapter/IMPLEMENTATION.jp
new file mode 100644
index 00000000..bb425b75
--- /dev/null
+++ b/fml/lib/IO/Adapter/IMPLEMENTATION.jp
@@ -0,0 +1,57 @@
+ 諸問題
+
+
+○ 問題: getline() と get_XXX() メソッドについて
+
+ファイルとそれ以外では事情がかなり異なることに留意することが重要である。
+
+* ファイル(スペース区切り)では
+
+ key1
+ key2 value2
+ key3 value3a value3b
+
+というデータ構造が多い。これは
+
+ ファイル = {
+ key1 => undef,
+ key2 => [ value2 ],
+ key3 => [ value3a, value3b ],
+ };
+
+という perl のデータ構造に相当するだろう。
+
+
+* 一方、/etc/group は : と , 区切りと
+
+ key:value1, value2
+
+いう点を考えると、上のファイルと一見同様だが、
+
+ $obj = new IO::Adapter 'unix.group:wheel';
+
+という場合は、
+
+ wheel グループ = {
+
+ root => undef,
+ だれか => undef,
+ ....
+
+ };
+
+もしくは
+
+ wheel グループ = [
+
+ root => undef,
+ だれか => undef,
+ ....
+
+ ];
+
+
+だが、汎用性を考えればハッシュにあわせるべきだろう。
+
+----------
+$FML$
diff --git a/fml/lib/IO/Adapter/MySQL.pm b/fml/lib/IO/Adapter/MySQL.pm
index 1a5bc529..e48395e6 100644
--- a/fml/lib/IO/Adapter/MySQL.pm
+++ b/fml/lib/IO/Adapter/MySQL.pm
@@ -1,9 +1,9 @@
#-*- perl -*-
#
-# Copyright (C) 2000,2001 Ken'ichi Fukamachi
+# Copyright (C) 2000,2001,2002 Ken'ichi Fukamachi
# All rights reserved.
#
-# $FML: MySQL.pm,v 1.17 2001/12/22 09:21:13 fukachan Exp $
+# $FML: MySQL.pm,v 1.18 2001/12/24 07:40:57 fukachan Exp $
#
@@ -145,7 +145,7 @@ sub setpos
}
# discard
- while ($i-- > 0) { $self->get_next_value();}
+ while ($i-- > 0) { $self->get_next_key();}
}
@@ -193,7 +193,7 @@ Ken'ichi Fukamachi
=head1 COPYRIGHT
-Copyright (C) 2001 Ken'ichi Fukamachi
+Copyright (C) 2000,2001,2002 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.