root/lib/Iterator.pm

Revision 127, 2.8 kB (checked in by cholt, 10 months ago)

major maker update, gff passthrough, evaluator integration, tblastx, ncbi, error control

Line 
1 #----------------------------------------------------------------------------
2 #----                             Iterator                               ----
3 #----------------------------------------------------------------------------
4 package Iterator;
5 use strict;
6 use vars qw(@ISA @EXPORT $VERSION);
7 use Exporter;
8 use PostData;
9 use FileHandle;
10 @ISA = qw(
11        );
12
13 #------------------------------------------------------------------------------
14 #--------------------------------- METHODS ------------------------------------
15 #------------------------------------------------------------------------------
16 sub new {
17         my $class = shift;
18         my $arg   = shift;
19
20         my $self = {};
21         bless $self;
22
23         $self->fileHandle($arg);
24
25         return $self;
26 }
27 #-------------------------------------------------------------------------------
28 sub nextEntry {
29         my $self = shift;
30
31         my $fh = $self->fileHandle();
32         my $line;
33         while($line = <$fh>){
34                 $self->offsetInFile(1);
35                 return $line;
36         }
37         $fh->close();
38         return undef;
39 }
40 #-------------------------------------------------------------------------------
41 sub offsetInFile {
42         my $self      = shift;
43         my $increment = shift;
44
45         if (defined($increment) && defined($self->{offsetInFile})){
46                 $self->{offsetInFile} += $increment;
47         }
48         elsif (defined($increment) && !defined($self->{offsetInFile})) {
49                 $self->{offsetInFile} = $increment -1;
50                
51         }
52         else {
53                 return $self->{offsetInFile};
54         }
55 }
56 #-------------------------------------------------------------------------------
57 sub fileHandle {
58         my $self = shift;
59         my $arg  = shift;
60        
61
62         if    (defined($arg) && ref($arg) eq 'FileHandle'){
63                  $self->{fileHandle} = $arg;
64         }
65         elsif (defined($arg) && -e $arg){
66                 my $fh = new FileHandle();
67                    $fh->open("$arg");
68
69                 $self->{fileHandle} = $fh;
70         }
71         elsif (!defined($arg) && defined($self->{fileHandle})){
72                 return $self->{fileHandle};
73         }
74         else {
75                 die "unknown event in Iterator::fileHandle\n";
76         }
77 }
78 #-------------------------------------------------------------------------------
79 #------------------------------ FUNCTIONS --------------------------------------
80 #-------------------------------------------------------------------------------
81 #-------------------------------------------------------------------------------
82 sub AUTOLOAD {
83         my ($self, $arg) = @_;
84
85         my $caller = caller();
86         use vars qw($AUTOLOAD);
87         my ($call) = $AUTOLOAD =~/.*\:\:(\w+)$/;
88         $call =~/DESTROY/ && return;
89
90         print STDERR "Iterator::AutoLoader called for: ",
91               "\$self->$call","()\n";
92         print STDERR "call to AutoLoader issued from: ", $caller, "\n";
93
94         if (defined($arg)){
95                 $self->{$call} = $arg;
96         }
97         else {
98                 return $self->{$call};
99         }
100 }
101 #------------------------------------------------------------------------
102
103 1;
104
105
Note: See TracBrowser for help on using the browser.