File Coverage

blib/lib/HTML/FormHandler/Field/PrimaryKey.pm
Criterion Covered Total %
statement 10 12 83.3
branch 2 4 50.0
condition n/a
subroutine 3 3 100.0
pod 0 1 0.0
total 15 20 75.0


line stmt bran cond sub pod time code
1             package HTML::FormHandler::Field::PrimaryKey;
2             # ABSTRACT: primary key field
3             $HTML::FormHandler::Field::PrimaryKey::VERSION = '0.40067';
4 29     29   943 use Moose;
  29         47  
  29         214  
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 16     16 0 30 my $self = shift;
15 16 50       477 if ( $self->has_parent ) {
16 16 50       369 if ( $self->parent->has_primary_key ) {
17 0         0 push @{ $self->parent->primary_key }, $self;
  0         0  
18             }
19             else {
20 16         376 $self->parent->primary_key( [ $self ] );
21             }
22             }
23             }
24              
25             __PACKAGE__->meta->make_immutable;
26 29     29   136216 use namespace::autoclean;
  29         53  
  29         282  
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.40067
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) 2016 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