File Coverage

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