The following code connects to a linksys router and resets the connection. I can't seem to find the proper way to access the contents of the HTML::Form::InputText object without accessing it's internal data structure.


This is part of the expression in question:
my $status = $1 if $input->{value_name}

Anybody know a proper way to get this value?

Thanks,
Randy.

--

#!/usr/bin/perl

use strict;
use warnings;

use WWW::Mechanize;


use constant URL => 'http://192.168.0.1/Status.htm';


{#  username and password
    package MyMech;
    our @ISA = qw(WWW::Mechanize);

    sub get_basic_credentials {
        my($self, $realm, $uri) = @_;
        return ('username', 'password');
    }
}

# Fetch status page
my $mech = MyMech->new();
my $resp = $mech->get( URL );
die "Can't connect" unless $resp->is_success();

# Determine current connection status
my $form = $mech->form_number( 1 ) or die "Can't select form";
my $input = $form->find_input( 'pppoeAct' ) or die "Can't find input";
my $status = $1 if $input->{value_name} =~ /Status: (Connected|Connecting|Disconnected)/;


print "$status\n";

# If connected, reset connection
if ($status eq 'Connected') {
    my $resp = $mech->click();
    if ($resp->is_success) {
        sleep( 5 );
        $resp = $mech->get( URL );
        die "Can't re-get page" unless $resp->is_success;
        $resp = $mech->click();
        die "Failed to reconnect" unless $resp->is_success;
    } else { die "Failed to disconnect"; }
} else { die "Unexpectedly" }


print "done.\n";




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to