Skip to content

Instantly share code, notes, and snippets.

@t-kashima
Created November 13, 2011 19:07
Show Gist options
  • Save t-kashima/1362511 to your computer and use it in GitHub Desktop.
Save t-kashima/1362511 to your computer and use it in GitHub Desktop.
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