Created
November 13, 2011 19:07
-
-
Save t-kashima/1362511 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package WWW::Kadai::Auth::Simple; | |
use strict; | |
use warnings; | |
use CGI::Carp qw(croak); | |
use base qw(Class::Accessor::Fast Class::ErrorHandler); | |
use WWW::Mechanize; | |
use URI; | |
our $VERSION = 0.01; | |
sub login { | |
my $self = shift; | |
my $username = shift or croak "Invalid argument (no username)"; | |
my $password = shift or croak "Invalid argument (no password)"; | |
my $mech = WWW::Mechanize->new; | |
$username = lc $username; | |
$username = "s" . $username if ($username !~ /^s/); | |
$mech->get(URI->new('http://www.lib.kagawa-u.ac.jp/mylibrary/')); | |
$mech->submit_form( | |
form_number => 1, | |
fields => { | |
username => $username, | |
password => $password, | |
}, | |
); | |
return $self->error($mech->status_line) unless $mech->success; | |
return $self->error('Authentication failured') if ($mech->content =~ /SIMPLE HELP/); | |
return $username; | |
} | |
1; | |
__END__ | |
=head1 NAME | |
WWW::Kadai::Auth::Simple - Perl intaface to the Kagawa University Authentication | |
=head1 VERSION | |
Version 0.01 | |
=head1 SYNOPSIS | |
use WWW::Kadai::Auth::Simple; | |
my $kadai = WWW::Kadai::Auth::Simple->new; | |
my $username = $kadai->login('username', 'password') or die "Couldn't login"; | |
=head1 DESCRIPTION | |
A simple interface for using the Kadai University Library Authentication |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment