| 1 |
package HTML::FormHandler::Field::PrimaryKey; |
| 2 |
# ABSTRACT: primary key field |
| 3 |
$HTML::FormHandler::Field::PrimaryKey::VERSION = '0.410002'; |
| 4 |
use Moose; |
| 5 |
extends 'HTML::FormHandler::Field'; |
| 6 |
|
| 7 |
|
| 8 |
has 'is_primary_key' => ( isa => 'Bool', is => 'ro', default => '1' ); |
| 9 |
has '+widget' => ( default => 'Hidden' ); |
| 10 |
has '+do_label' => ( default => 0 ); |
| 11 |
has '+no_value_if_empty' => ( default => 1 ); |
| 12 |
|
| 13 |
sub BUILD { |
| 14 |
my $self = shift; |
| 15 |
if ( $self->has_parent ) { |
| 16 |
if ( $self->parent->has_primary_key ) { |
| 17 |
push @{ $self->parent->primary_key }, $self; |
| 18 |
} |
| 19 |
else { |
| 20 |
$self->parent->primary_key( [ $self ] ); |
| 21 |
} |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
__PACKAGE__->meta->make_immutable; |
| 26 |
use namespace::autoclean; |
| 27 |
1; |
| 28 |
|
| 29 |
__END__ |
| 30 |
|
| 31 |
=pod |
| 32 |
|
| 33 |
=encoding UTF-8 |
| 34 |
|
| 35 |
=head1 NAME |
| 36 |
|
| 37 |
HTML::FormHandler::Field::PrimaryKey - primary key field |
| 38 |
|
| 39 |
=head1 VERSION |
| 40 |
|
| 41 |
version 0.410002 |
| 42 |
|
| 43 |
=head1 SYNOPSIS |
| 44 |
|
| 45 |
This field is for providing the primary key for Repeatable fields: |
| 46 |
|
| 47 |
has_field 'addresses' => ( type => 'Repeatable' ); |
| 48 |
has_field 'addresses.address_id' => ( type => 'PrimaryKey' ); |
| 49 |
|
| 50 |
Do not use this field to hold the primary key of the form's main db object (item). |
| 51 |
That primary key is in the 'item_id' attribute. |
| 52 |
|
| 53 |
=head1 AUTHOR |
| 54 |
|
| 55 |
FormHandler Contributors - see HTML::FormHandler |
| 56 |
|
| 57 |
=head1 COPYRIGHT AND LICENSE |
| 58 |
|
| 59 |
This software is copyright (c) 2017 by Gerda Shank. |
| 60 |
|
| 61 |
This is free software; you can redistribute it and/or modify it under |
| 62 |
the same terms as the Perl 5 programming language system itself. |
| 63 |
|
| 64 |
=cut |