| 1 | # | ||
| 2 | # Copyright (C) 2004 Jörg Tiedemann <joerg@stp.ling.uu.se> | ||
| 3 | # | ||
| 4 | # This program is free software; you can redistribute it and/or modify | ||
| 5 | # it under the terms of the GNU General Public License as published by | ||
| 6 | # the Free Software Foundation; either version 2 of the License, or | ||
| 7 | # (at your option) any later version. | ||
| 8 | # | ||
| 9 | # This program is distributed in the hope that it will be useful, | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | # GNU General Public License for more details. | ||
| 13 | # | ||
| 14 | # You should have received a copy of the GNU General Public License | ||
| 15 | # along with this program; if not, write to the Free Software | ||
| 16 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 17 | # | ||
| 18 | # -*-perl-*- | ||
| 19 | # $Id$ | ||
| 20 | |||
| 21 | |||
| 22 | package Uplug::IO::LWA; | ||
| 23 | |||
| 24 | use strict; | ||
| 25 | use vars qw(@ISA); | ||
| 26 | use vars qw(%StreamOptions); | ||
| 27 | use Uplug::IO::Text; | ||
| 28 | use Uplug::IO::Any; | ||
| 29 | # use Uplug::Data; | ||
| 30 | # use Uplug::Data::Tree; | ||
| 31 | |||
| 32 | @ISA = qw( Uplug::IO ); | ||
| 33 | |||
| 34 | # stream options and their default values!! | ||
| 35 | |||
| 36 | |||
| 37 | sub open{ | ||
| 38 | my $self=shift; | ||
| 39 | if ($self->SUPER::open(@_)){ | ||
| 40 | my $src=$self->options(); | ||
| 41 | $src->{file}=$self->option('source file'); | ||
| 42 | $self->{source}=Uplug::IO::Any->new('text',$src); | ||
| 43 | if (not $self->{source}->open(@_[0],$src)){ | ||
| 44 | return 0; | ||
| 45 | } | ||
| 46 | my $trg=$self->options(); | ||
| 47 | $trg->{file}=$self->option('target file'); | ||
| 48 | $self->{target}=Uplug::IO::Any->new('text',$trg); | ||
| 49 | if (not $self->{target}->open(@_[0],$trg)){ | ||
| 50 | return 0; | ||
| 51 | } | ||
| 52 | return 1; | ||
| 53 | } | ||
| 54 | return 0; | ||
| 55 | } | ||
| 56 | |||
| 57 | |||
| 58 | sub write{ | ||
| 59 | my $self=shift; | ||
| 60 | my ($data)=@_; | ||
| 61 | $self->Uplug::IO::write($data); | ||
| 62 | my $cont=$data->content('source'); | ||
| 63 | $self->{source}->write($cont); | ||
| 64 | my $cont=$data->content('target'); | ||
| 65 | $self->{target}->write($cont); | ||
| 66 | } | ||
| 67 | |||
| 68 | |||
| 69 | sub read{ | ||
| 70 | |||
| 71 | print STDERR "# Uplug::IO::LWA: read doesn't work\n"; | ||
| 72 | return 0; | ||
| 73 | } | ||
| 74 | |||
| 75 | sub close{ | ||
| 76 | my $self=shift; | ||
| 77 | $self->{source}->close(); | ||
| 78 | $self->{target}->close(); | ||
| 79 | $self->SUPER::close(@_); | ||
| 80 | } |