Moritz Lenz
and 1 contributors


WebService::Libris - Access book meta data from


Version 0.08

Note that the API is still subject to change.


    use WebService::Libris;
    use 5.010;
    binmode STDOUT, ':encoding(UTF-8)';

    my $book = WebService::Libris->new(
        type => 'book',
        # Libris ID
        id   => '9604288',
        # optional but recommended:
        cache_dir = '/tmp/webservice-libris/',
    print $book->title;

    my $books = WebService::Libris->search(
        term    => 'Astrid Lindgren',
        page    => 1,
    while (my $b = $books->next) {
        say $b->title;
        say '  isbn: ', $b->isbn;
        say '  date: ', $b->date;


The Swedish public libraries and the national library of Sweden have a common catalogue containing meta data of the books they have available.

This includes many contemporary as well as historical books.

The catalogue is available online at, and can be queried with a public API.

This module is a wrapper around two of their APIs (xsearch and RDF responses).



    my $obj = WebService::Libris->new(
        type => 'author',
        id   => '246603',

Creates an object of the WebService::Libris class or a subclass thereof (denoted by type in the argument list). type can currently be one of (synonyms on one line)

    auth author
    bib book

The id argument is mandatory, and must contain the Libris ID of the object you want to retrieve. If you don't know the Libris ID, use one of the search functions instead.

    my $hashref = WebService::Libris->direct_search(
        term    => 'Your Searchterms Here',
        page    => 1,   # page size is 200
        full    => 1,   # return all available information

Returns a hashref directly from the JSON response of the xsearch API described at

This is more efficient than a WebService::Libris->search call, because it does only one query (whereas ->search does one additional request per result object), but it's not as convenient, and does not allow browsing of related entities (such as authors and libraries).

    my @books = WebService::Libris->search(
        term    => 'Your Search Term Here',
        page    => 1,
    for my $book (@books) {
        say $book->title;

Searches the xsearch API for arbitrary search terms, and returns a WebService::Libris::Collection of books.

See the direct_search method above for a short discussion.


    my $book = WebService::Libris->search_for_isbn('9170370192');

Looks up a book by ISBN

Less interesting methods

The following methods aren't usually useful for the casual user, more for those who want to extend or subclass this module.


Returns the RDF resource URL for the current object. Mostly useful for internal purposes.


Returns the Mojo::DOM object from the web services response. Does a request to the web service if no DOM was stored previously.

Only useful for you if you want to extract more data from a response than the object itself provides.


Returns the libris ID of the object. Only makes sense for subclasses.


Returns the short type name (bib, auth, library). Only makes sense for subclasses.


Must be overridden in a subclass to return a list of the last two junks of the RDF resource URL, that is the short type name and the libris ID.


Moritz Lenz, <moritz at>


Please report any bugs or feature requests at


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

    perldoc WebService::Libris

You can also look for information at:


Nearly no error checking is done. So beware!


Thanks go to the Kungliga biblioteket (National Library of Sweden) for providing the service and API.


Copyright 2011 Moritz Lenz.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.