Skip to content

Instantly share code, notes, and snippets.

@TristinDavis
Forked from dvinciguerra/www-fgen.pl
Created November 17, 2012 18:49
Show Gist options
  • Save TristinDavis/4098757 to your computer and use it in GitHub Desktop.
Save TristinDavis/4098757 to your computer and use it in GitHub Desktop.
Example of using WWW::Mechanize
package WWW::FGen;
use WWW::Mechanize;
# constructor
sub new {
my $class = shift;
return bless {
_mechanize => WWW::Mechanize->new( agent => 'Perl of Love' ),
_url => 'http://mendel.cs.rhul.ac.uk/mendel.php?topic=fgen-file',
_file => $file,
_program_name => 'fgenesh',
_org => 'c',
_sequence => '',
_query => undef,
_result => undef,
_output => '',
}, $class;
}
# mechanize accessor
sub mechanize {
$_[0]->{_mechanize} = $_[1] if defined $_[1];
return shift->{_mechanize};
}
# query accessor
sub query {
$_[0]->{_query} = $_[1] if defined $_[1];
return shift->{_query};
}
# result accessor
sub result {
$_[0]->{_result} = $_[1] if defined $_[1];
return shift->{_result};
}
# url accessor
sub url {
$_[0]->{_url} = $_[1] if defined $_[1];
return shift->{_url};
}
# execute search
sub search {
my $self = shift;
# getting page source L<HTTP::Response>
my $result = $self->mechanize->get(
$self->url
);
$self->query( $result->content );
# running search
my $search = $self->mechanize->submit_form(
form_number => 1,
fields => {
file => $self->{_file},
program_name => $self->{_program_name},
org => $self->{_org},
},
);
$self->result( $search->content );
# debug result
print $search->content;
#print $result->content;
}
package main;
my $app = WWW::FGen->new;
$app->search;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment