~ubuntu-branches/ubuntu/utopic/libhtml-formhandler-model-dbic-perl/utopic

« back to all changes in this revision

Viewing changes to t/lib/BookDB/Form/Book2PK.pm

  • Committer: Package Import Robot
  • Author(s): Dominique Dumont, Salvatore Bonaccorso, Dominique Dumont
  • Date: 2013-10-13 18:35:48 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20131013183548-t4f9rp4ezb123ahk
Tags: 0.28-1
[ Salvatore Bonaccorso ]
* Change Vcs-Git to canonical URI (git://anonscm.debian.org)
* Change search.cpan.org based URIs to metacpan.org based URIs

[ Dominique Dumont ]
* Imported Upstream version 0.28
* bumped compat to 9
* control:
  * added version dep on libdbix-class-perl
  * bump std-version to 3.9.4
  + build-dep in libtest-exception-perl
* copyright: updated years

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package BookDB::Form::Book2PK;
 
2
use HTML::FormHandler::Moose;
 
3
extends 'HTML::FormHandler::Model::DBIC';
 
4
 
 
5
with 'HTML::FormHandler::Widget::Theme::Bootstrap';
 
6
 
 
7
=head1 NAME
 
8
 
 
9
Form object for the Book Controller
 
10
 
 
11
=head1 SYNOPSIS
 
12
 
 
13
Form used for book/add and book/edit actions
 
14
 
 
15
=head1 DESCRIPTION
 
16
 
 
17
Catalyst Form.
 
18
 
 
19
=cut
 
20
 
 
21
has '+item_class'        => ( default => 'Book2PK' );
 
22
 
 
23
has_field 'title' => (
 
24
    type             => 'Text',
 
25
    required         => 1,
 
26
    required_message => 'A book must have a title.',
 
27
    label            => 'Title',
 
28
);
 
29
 
 
30
has_field 'publisher' => (
 
31
    type  => 'Text',
 
32
    label => 'Publisher',
 
33
);
 
34
 
 
35
# has_many relationship pointing to mapping table
 
36
has_field 'isbn' => (
 
37
    type     => 'Text',
 
38
    label    => 'ISBN',
 
39
    unique   => 1,
 
40
    required => 1,
 
41
);
 
42
has_field 'year' => (
 
43
    type        => 'Integer',
 
44
    range_start => '1900',
 
45
    range_end   => '2020',
 
46
    label       => 'Year',
 
47
    required    => 1,
 
48
);
 
49
has_field 'pages' => (
 
50
    type  => 'Integer',
 
51
    label => 'Pages',
 
52
);
 
53
 
 
54
has_field submit => ( type => 'Submit', value => 'Update', element_class => ['btn'] );
 
55
 
 
56
sub validate_year {
 
57
    my ( $self, $field ) = @_;
 
58
    $field->add_error('Invalid year')
 
59
      if ( ( $field->value > 3000 ) || ( $field->value < 1600 ) );
 
60
}
 
61
 
 
62
=head1 AUTHOR
 
63
 
 
64
Gerda Shank
 
65
 
 
66
=head1 LICENSE AND COPYRIGHT
 
67
 
 
68
This module is free software; you can redistribute it and/or
 
69
modify it under the same terms as Perl itself. See L<perlartistic>.
 
70
 
 
71
=cut
 
72
 
 
73
__PACKAGE__->meta->make_immutable;
 
74
no HTML::FormHandler::Moose;
 
75
1;