NAME

WebService::UWO::Directory::Student - Perl module for searching the UWO student directory

VERSION

Version 1.004 ($Id: Student.pm 10608 2009-12-23 16:06:17Z FREQUENCY@cpan.org $)

DESCRIPTION

This module provides a Perl interface to the public directory search system which lists current students at the University of Western Ontario. For more information, see the web interface at http://uwo.ca/westerndir/.

SYNOPSIS

Example code:

    use WebService::UWO::Directory::Student;

    # Create Perl interface to API
    my $dir = WebService::UWO::Directory::Student->new;

    # Look up a student by name
    my $results = $dir->lookup({
      first => 'John',
      last  => 'S'
    });

    # Go through results
    foreach my $stu (@{$results}) {
      print 'email: ' . $stu->email . "\n";
    }

    # Reverse a lookup (use e-mail to find record)
    my $reverse = $dir->lookup({
      email => 'jsmith@uwo.ca'
    });

    if (defined $reverse) {
      print "Found: $reverse\n";
    }

COMPATIBILITY

This module was tested under Perl 5.10.0, using Debian Linux. However, because it's Pure Perl and doesn't do anything too obscure, it should be compatible with any version of Perl that supports its prerequisite modules.

If you encounter any problems on a different version or architecture, please contact the maintainer.

METHODS

new

  WebService::UWO::Directory::Student->new( \%params )

Creates a UWO::Directory::Student search object, which uses a given web page and server. Being that this module is developed to target UWO's in-house system, the defaults should suffice.

The parameters available are:

    my $dir = UWO::Directory::Student->new({
      url    => 'http://uwo.ca/cgi-bin/dsgw/whois2html2',
      server => 'localhost',
    });

Which instantiates a UWO::Directory::Student instance using url as the frontend and server as the "black-box" backend.

lookup

  $dir->lookup( \%params )

Uses a WebService::UWO::Directory::Student search object to locate a given person based on either their name (first and/or last) or their e-mail address (email).

The module uses the following procedure to locate users:

  1. If an e-mail address is provided:

    1. The address is deconstructed into a first initial and the portion of the last name. (According to the regular expression ^(\w)([^\d]+)([\d]*)$)

    2. The partial name is looked up in the directory.

    3. The resulting records are tested against the e-mail address. If the e-mail address matches a given record, an anonymous hash containing user information is returned. The lookup returns a false value (0) upon failure.

  2. If first and/or last names are provided:

    1. The name is searched using the normal interface (using the query last_name,first_name) and the results are returned as an array reference. If there are no results, the method returns a false value (0).

Example code:

    # Look up "John S" in the student directory
    my $results = $dir->lookup({
      first => 'John',
      last  => 'S'
    });

    # Look up jsmith@uwo.ca
    my $reverse = $dir->lookup({
      email => 'jsmith@uwo.ca'
    });

This method is not guaranteed to return results. Keep in mind that if no results are found, the return code will be 0, so make sure to check return codes before attempting to dereference the expected array/hash.

Record Format

Each returned record will be a hash with the following fields:

  • last_name,

  • given_name (which may contain middle names)

  • email (the registered @uwo.ca e-mail address)

  • faculty

You may explore this using Data::Dumper.

UNSUPPORTED API

WebService::UWO::Directory::Student provides access to some internal methods used to retrieve and process raw data from the directory server. Its behaviour is subject to change and may be finalized later as the need arises.

_query

  $dir->_query( $query, $ua )

This method performs an HTTP lookup using LWP::UserAgent and returns a SCALAR reference to the returned page content. A LWP::UserAgent object may optionally be passed, which is particularly useful if a proxy is required to access the Internet.

Please note that if a LWP::UserAgent is passed, the User-Agent string will not be modified. In normal operation, this module reports its user agent as 'WebService::UWO::Directory::Student/' . $VERSION.

_parse

  WebService::UWO::Directory::Student::_parse( $response )

This method processes the HTML content retrieved by _query method and returns an ARRAY reference containing HASH references to the result set. This is most likely only useful for testing purposes.

AUTHOR

Jonathan Yu <jawnsy@cpan.org>

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc WebService::UWO::Directory::Student

You can also look for information at:

REPOSITORY

You can access the most recent development version of this module at:

http://svn.ali.as/cpan/trunk/WebService-UWO-Directory-Student

If you are a CPAN developer and would like to make modifications to the code base, please contact Adam Kennedy <adamk@cpan.org>, the repository administrator. I only ask that you contact me first to discuss the changes you wish to make to the distribution.

FEEDBACK

Please send relevant comments, rotten tomatoes and suggestions directly to the maintainer noted above.

If you have a bug report or feature request, please file them on the CPAN Request Tracker at http://rt.cpan.org. If you are able to submit your bug report in the form of failing unit tests, you are strongly encouraged to do so.

SEE ALSO

http://uwo.ca/westerndir/index-student.html, the site this module uses to query the database

CAVEATS

KNOWN BUGS

There are no known bugs as of this release.

LIMITATIONS

  • This module is only able to access partial student records since students must give consent for their contact information to be published on the web. For more, see http://www3.registrar.uwo.ca/InfoServices/DirectoryRemoval.cfm.

  • Some students change their name (for example, a marriage), while retainining the same email address. This means their email addresses cannot be effectively reverse-searched.

  • This module has not been very thoroughly tested for memory consumption. It does a lot of copying that should be optimized, however, it is probably not necessary for most uses.

LICENSE

In a perfect world, I could just say that this package and all of the code it contains is Public Domain. It's a bit more complicated than that; you'll have to read the included LICENSE file to get the full details.

DISCLAIMER OF WARRANTY

The software is provided "AS IS", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.