DBIx::Class::InflateColumn::ISBN - Auto-create Business::ISBN objects from columns.


DBIx-Class-InflateColumn-ISBN documentation Contained in the DBIx-Class-InflateColumn-ISBN distribution.

Index


Code Index:

NAME

Top

DBIx::Class::InflateColumn::ISBN - Auto-create Business::ISBN objects from columns.

VERSION

Top

Version 0.04000

SYNOPSIS

Top

Load this component and declare columns as ISBNs with the appropriate format.

    package Library;
    __PACKAGE__->load_components(qw/InflateColumn::ISBN Core/);
    __PACKAGE__->add_columns(
        isbn => {
            data_type => 'varchar',
            size => 13,
            is_nullable => 0,
            is_isbn => 1,
            as_string => 0,
        }
    );

It has to be a varchar rather than a simple integer given that it is possible for ISBNs to contain the character X. Old style ISBNs are 10 characters, not including hyphens, but new style ones are 13 characters.

The as_string attribute is optional, and if set to 1 then values will be stored in the database with hyphens in the appopriate places. In this case, an extra 3 characters will be required.

Then you can treat the specified column as a Business::ISBN object.

    print 'ISBN: ', $book->isbn->as_string;
    print 'Publisher code: ', $book->isbn->publisher_code;

METHODS

Top

isbn_class

Arguments: $class

Gets/sets the address class that the columns should be inflated into. The default class is Business::ISBN and only that is currently supported.

register_column

Chains with register_column in DBIx::Class::Row, and sets up ISBN columns appropriately. This would not normally be called directly by end users.

AUTHOR

Top

K. J. Cheetham <jamie @ shadowcatsystems.co.uk>

BUGS

Top

Please report any bugs or feature requests to bug-dbix-class-inflatecolumn-ISBN at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBIx-Class-InflateColumn-ISBN. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

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

    perldoc DBIx::Class::InflateColumn::ISBN

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/DBIx-Class-InflateColumn-ISBN

* CPAN Ratings

http://cpanratings.perl.org/d/DBIx-Class-InflateColumn-ISBN

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=DBIx-Class-InflateColumn-ISBN

* Search CPAN

http://search.cpan.org/dist/DBIx-Class-InflateColumn-ISBN

SEE ALSO

Top

Business::ISBN

DBIx::Class::InflateColumn

WWW::Scraper::ISBN

COPYRIGHT & LICENSE

Top


DBIx-Class-InflateColumn-ISBN documentation Contained in the DBIx-Class-InflateColumn-ISBN distribution.
package DBIx::Class::InflateColumn::ISBN;

use warnings;
use strict;

our $VERSION = '0.04000';

use base qw/DBIx::Class/;
__PACKAGE__->mk_classdata('isbn_class');
__PACKAGE__->isbn_class('Business::ISBN');

sub register_column {
    my ($self, $column, $info, @rest) = @_;
    $self->next::method($column, $info, @rest);

    return unless defined $info->{'is_isbn'};

    if ( $info->{'size'} && ($info->{'size'} < 10 ||
      ($info->{'as_string'} && $info->{'size'} < 13)) ) {
        $self->throw_exception("ISBN field datatype is too small");
    }
    $self->throw_exception("ISBN field datatype must not be integer")
        if ($info->{'data_type'} eq 'integer');

    my $isbn_class = $info->{'isbn_class'} || $self->isbn_class || 'Business::ISBN';

    eval "use $isbn_class";
    $self->throw_exception("Error loading $isbn_class: $@") if $@;

    $self->inflate_column(
        $column => {
            inflate => sub {
                return $isbn_class->new(sprintf("%010s", shift));
            },
            deflate => sub {
                $info->{'as_string'} ? shift->as_string : shift->isbn;
            },
        }
    );
}

1; # End of DBIx::Class::InflateColumn::ISBN