[Bps-public-commit] r17878 - Net-Trac/trunk/lib/Net/Trac
jesse at bestpractical.com
jesse at bestpractical.com
Wed Jan 21 19:16:45 EST 2009
Author: jesse
Date: Wed Jan 21 19:16:45 2009
New Revision: 17878
Modified:
Net-Trac/trunk/lib/Net/Trac/Connection.pm
Log:
* Support login with Trac's cookie auth
Modified: Net-Trac/trunk/lib/Net/Trac/Connection.pm
==============================================================================
--- Net-Trac/trunk/lib/Net/Trac/Connection.pm (original)
+++ Net-Trac/trunk/lib/Net/Trac/Connection.pm Wed Jan 21 19:16:45 2009
@@ -114,11 +114,32 @@
my $self = shift;
if ( !defined $self->logged_in ) {
$self->_fetch("/login") or return;
+
+ my ($form, $form_num) = $self->_find_login_form();
+ if ($form_num) {
+ $self->mech->submit_form(
+ form_number => $form_num,
+ fields => { user => $self->user, password => $self->password, submit => 1 }
+ );
+ }
+
+
$self->logged_in(1);
}
return $self->logged_in;
}
+
+sub _find_login_form {
+ my $self = shift;
+ my $i = 1;
+ for my $form ( $self->mech->forms() ) {
+ return ($form,$i) if $form->find_input('user');
+ $i++;
+ }
+}
+
+
=head1 PRIVATE METHODS
=head2 _fetch URL
@@ -135,7 +156,7 @@
my $abs_url = $self->url . $query;
$self->mech->get($abs_url);
- if ( $self->_warn_on_error($abs_url) ) { return }
+ if ( $self->_warn_on_error($abs_url) ) { warn "FAIL"; return }
else { return $self->mech->content }
}
More information about the Bps-public-commit
mailing list