sub parse { my $self = shift; my @opts = @_; my %opts; if ( ! @opts || scalar @opts % 2 ) { $self->COMPLAIN("bad number of arguments."); return; } else { %opts = @opts; if ( ! $opts{-format} || ! grep(ucfirst($opts{-format}), @parsers) ) { $self->COMPLAIN("no valid format specified."); return; } if ( $opts{-file} && ( ! -T $opts{-file} || ! -r $opts{-file} ) ) { $self->COMPLAIN("file not found, not a text file, or not readable"); return; } elsif ( ! $opts{-file} && ! $opts{-string} ) { $self->COMPLAIN("no data source specified."); return; } my $lib = ref $self; $lib .= '::' . ucfirst($opts{-format}); eval "require $lib"; my $parser = new $lib; if ( $opts{-file} && $parser->can('from_handle') ) { open(FH, $opts{-file}); $opts{-handle} = \*FH; return $parser->from_handle(%opts); } if ( $opts{-string} && $parser->can('from_string') ) { return $parser->from_string(%opts); } $self->COMPLAIN("the parser can't handle the data source specified"); return; } }