diff options
| author | fukachan <fukachan> | 2001-01-28 07:42:45 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2001-01-28 07:42:45 +0000 |
| commit | ef10af430c24265d1b8fec4373d566e27c22508a (patch) | |
| tree | bc791bda4d5c5759801085f4605172e790d4d5f1 | |
| parent | 7ee280e93c6797fef8ab87454869272bd2df3526 (diff) | |
| download | fml8-ef10af430c24265d1b8fec4373d566e27c22508a.tar.gz fml8-ef10af430c24265d1b8fec4373d566e27c22508a.tar.bz2 fml8-ef10af430c24265d1b8fec4373d566e27c22508a.zip | |
clean up more to fit adapter structure
| -rw-r--r-- | fml/lib/IO/Adapter/Array.pm | 4 | ||||
| -rw-r--r-- | fml/lib/IO/Adapter/File.pm | 8 | ||||
| -rw-r--r-- | fml/lib/IO/MapAdapter.pm | 135 |
3 files changed, 23 insertions, 124 deletions
diff --git a/fml/lib/IO/Adapter/Array.pm b/fml/lib/IO/Adapter/Array.pm index 7bfea79b..3ec33bd3 100644 --- a/fml/lib/IO/Adapter/Array.pm +++ b/fml/lib/IO/Adapter/Array.pm @@ -41,6 +41,10 @@ sub open } +# raw line reading +sub getline { get_next_value(@_);} + + sub get_next_value { my ($self, $args) = @_; diff --git a/fml/lib/IO/Adapter/File.pm b/fml/lib/IO/Adapter/File.pm index 73c17a69..6e77b8ba 100644 --- a/fml/lib/IO/Adapter/File.pm +++ b/fml/lib/IO/Adapter/File.pm @@ -52,6 +52,14 @@ my $ec = 0; sub line_count { my ($self) = @_; return "${ec}/${c}";} +sub getline +{ + my ($self) = @_; + my $fh = $self->{_fh}; + $fh->getline; +} + + sub get_next_value { my ($self) = @_; diff --git a/fml/lib/IO/MapAdapter.pm b/fml/lib/IO/MapAdapter.pm index e70861e0..58ff89e5 100644 --- a/fml/lib/IO/MapAdapter.pm +++ b/fml/lib/IO/MapAdapter.pm @@ -106,6 +106,11 @@ sub new $pkg = 'IO::Adapter::Array'; $me->{_name} = $1; $me->{_type} = 'unix.group'; + + # emulate an array on memory + my (@x) = getgrnam( $me->{_name} ); + my (@members) = split ' ', $x[3]; + $me->{_array_reference} = \@members; } elsif ($map =~ /(ldap|mysql|postgresql):(\S+)/) { $me->{_type} = $1; @@ -161,141 +166,23 @@ sub open if ($self->{'_type'} eq 'file') { $self->SUPER::open( { file => $self->{_file}, flag => $flag } ); } - elsif ($self->{'_type'} eq 'unix.group') { - my (@x) = getgrnam( $self->{_name} ); - my (@members) = split ' ', $x[3]; - $self->{_array_reference} = \@members; - $self->SUPER::open( { flag => $flag } ); - } - elsif ($self->{'_type'} eq 'array_reference') { - $self->SUPER::open( { flag => $flag } ); - } - elsif ($self->{'_type'} eq 'ldap' || - $self->{'_type'} eq 'mysql' || - $self->{'_type'} eq 'postgresql' - ) { - return undef; - } - else { - $self->_error_reason("Error: type=$self->{_type} is unknown type."); - } -} - - -# aliases for convenience -sub get_member { my ($self) = @_; $self->_get_address;} -sub get_active { my ($self) = @_; $self->_get_address;} -sub get_recipient { my ($self) = @_; $self->_get_address;} -sub _get_address -{ - my ($self) = @_; - - if ($self->{'_type'} eq 'file') { - $self->SUPER::get_next_value(); - } elsif ($self->{'_type'} eq 'unix.group' || $self->{'_type'} eq 'array_reference') { - $self->SUPER::get_next_value(); - } - elsif ($self->{'_type'} eq 'ldap' || - $self->{'_type'} eq 'mysql' || - $self->{'_type'} eq 'postgresql' - ) { - $self->_error_reason("Error: not yet implemented"); - return undef; - } - else { - $self->_error_reason("Error: type=$self->{_type} is unknown type."); - } -} - - -# raw line reading -sub getline -{ - my ($self) = @_; - - if ($self->{'_type'} eq 'file') { - my $fh = $self->{_fh}; - $fh->getline; - } - elsif ($self->{'_type'} eq 'unix.group') { - my $i = $self->{_counter}++; - my $ra = $self->{_members}; - defined $$ra[ $i ] ? $$ra[ $i ] : undef; + $self->SUPER::open( { flag => $flag } ); } - elsif ($self->{'_type'} eq 'ldap' || - $self->{'_type'} eq 'mysql' || - $self->{'_type'} eq 'postgresql' - ) { - $self->_error_reason("Error: not yet implemented"); + elsif ($self->{'_type'} =~ /^(ldap|mysql|postgresql)$/o) { return undef; } else { $self->_error_reason("Error: type=$self->{_type} is unknown type."); - return undef; } } -sub getpos -{ - my ($self) = @_; - - if ($self->{'_type'} eq 'file' || - $self->{'_type'} eq 'unix.group' || - $self->{'_type'} eq 'array_reference') { - $self->SUPER::getpos(); - } - else { - $self->_error_reason("Error: type=$self->{_type} is unknown type."); - } -} - - -sub setpos -{ - my ($self, $pos) = @_; - - if ($self->{'_type'} eq 'file' || - $self->{'_type'} eq 'unix.group' || - $self->{'_type'} eq 'array_reference') { - $self->SUPER::getpos($pos); - } - else { - $self->_error_reason("Error: type=$self->{_type} is unknown type."); - } -} - - -sub eof -{ - my ($self) = @_; - - if ($self->{'_type'} eq 'file' || - $self->{'_type'} eq 'unix.group' || - $self->{'_type'} eq 'array_reference') { - $self->SUPER::eof(); - } - else { - $self->_error_reason("Error: type=$self->{_type} is unknown type."); - } -} - - -sub close -{ - my ($self) = @_; - - if ($self->{'_type'} eq 'file' || - $self->{'_type'} eq 'unix.group' || - $self->{'_type'} eq 'array_reference') { - $self->SUPER::close(); - } - else { - $self->_error_reason("Error: type=$self->{_type} is unknown type."); - } -} +# aliases for convenience +sub get_member { my ($self) = @_; $self->get_next_value;} +sub get_active { my ($self) = @_; $self->get_next_value;} +sub get_recipient { my ($self) = @_; $self->get_next_value;} sub DESTROY |
