File: Book.pm

package info (click to toggle)
libhtml-formhandler-model-dbic-perl 0.29-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 640 kB
  • sloc: perl: 1,873; sql: 259; makefile: 14
file content (108 lines) | stat: -rw-r--r-- 2,188 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package BookDB::Form::Book;

use HTML::FormHandler::Moose;
extends 'HTML::FormHandler::Model::DBIC';

=head1 NAME

Form object for the Book Controller

=head1 SYNOPSIS

Form used for book/add and book/edit actions

=head1 DESCRIPTION

Catalyst Form.

=cut

has '+item_class'        => ( default => 'Book' );
has '+widget_name_space' => ( default => sub { ['BookDB::Form::Widget'] } );
has '+widget_wrapper'    => ( default => 'Para' );

has_field 'title' => (
    type             => 'Text',
    required         => 1,
    required_message => 'A book must have a title.',
    label            => 'Title',
    order           => '1',
);
has_field 'authors' => (
    type  => 'Multiple',
    label => 'Authors',
    label_column => 'full_name',
    order => '2',
);

has_field 'user_updated' => (
    type => 'Boolean'
);

# has_many relationship pointing to mapping table
has_field 'genres' => (
    type         => 'Multiple',
    label        => 'Genres',
    label_column => 'name',
    order        => '3',
);
has_field 'isbn' => (
    type   => 'Text',
    label  => 'ISBN',
    order  => '5',
    unique => 1,
);
has_field 'publisher' => (
    type  => 'Text',
    label => 'Publisher',
    order => '4',
);
has_field 'format' => (
    type  => 'Select',
    label => 'Format',
    order => '6',
);
has_field 'year' => (
    type        => 'Integer',
    range_start => '1900',
    range_end   => '2020',
    label       => 'Year',
    order       => '7',
);
has_field 'pages' => (
    type  => 'Integer',
    label => 'Pages',
    order => '8',
);
has_field 'comment' => (
    type  => 'Text',
    order => 9,
);

has_field 'borrower' => (
    type => 'Select',
    label_column => 'name_email',
);

has_field submit => ( type => 'Submit', value => 'Update' );

sub validate_year {
    my ( $self, $field ) = @_;
    $field->add_error('Invalid year')
      if ( ( $field->value > 3000 ) || ( $field->value < 1600 ) );
}

=head1 AUTHOR

Gerda Shank

=head1 LICENSE AND COPYRIGHT

This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlartistic>.

=cut

__PACKAGE__->meta->make_immutable;
no HTML::FormHandler::Moose;
1;