File Coverage

blib/lib/Dancer2/Plugin/FormValidator/Extension/DBIC.pm
Criterion Covered Total %
statement 3 4 75.0
branch n/a
condition n/a
subroutine 1 2 50.0
pod 0 1 0.0
total 4 7 57.1


line stmt bran cond sub pod time code
1              
2             use Moo;
3 1     1   1070  
  1         6342  
  1         5  
4             with 'Dancer2::Plugin::FormValidator::Role::Extension';
5              
6             our $VERSION = '1.00';
7              
8             has plugin_dbic => (
9             is => 'ro',
10             lazy => 1,
11             default => sub {
12             return shift->plugin->app->with_plugin('Dancer2::Plugin::DBIC');
13             }
14             );
15              
16             has schema => (
17             is => 'ro',
18             lazy => 1,
19             default => sub {
20             my $self = shift;
21             return $self->plugin_dbic->schema($self->config->{database});
22             }
23             );
24              
25             return {
26             exist => 'Dancer2::Plugin::FormValidator::Extension::DBIC::Exist',
27             unique => 'Dancer2::Plugin::FormValidator::Extension::DBIC::Unique',
28 0     0 0   };
29             }
30              
31             1;
32              
33             # ABSTRACT: Dancer2 FormValidator extension for checking field present in table row using DBIC.
34              
35             =pod
36              
37              
38             =encoding UTF-8
39              
40             =head1 NAME
41              
42             Dancer2::Plugin::FormValidator::Extension::DBIC - Dancer2 FormValidator extension for checking fields existence in table rows.
43              
44             =head1 VERSION
45              
46             version 1.00
47              
48             =head1 SYNOPSIS
49              
50             package Validator {
51             use Moo;
52              
53             with 'Dancer2::Plugin::FormValidator::Role::Profile';
54              
55             sub profile {
56             return {
57             username => [ qw(required unique:User,username) ],
58             };
59             };
60             }
61              
62              
63             =head1 DESCRIPTION
64              
65             This extension provides validators database data existence for Dancer2::Plugin::FormValidator.
66              
67             L<Dancer2::Plugin::FormValidator|https://metacpan.org/pod/Dancer2::Plugin::FormValidator>.
68              
69             =head1 CONFIGURATION
70              
71             set plugins => {
72             FormValidator => {
73             session => {
74             namespace => '_form_validator'
75             },
76             forms => {
77             login => 'Validator',
78             },
79             extensions => {
80             dbic => {
81             provider => 'Dancer2::Plugin::FormValidator::Extension::DBIC',
82             database => 'default' # DBIC database
83             }
84             }
85             },
86             };
87              
88             config.yml:
89              
90             ...
91             plugins:
92             FormValidator:
93             session:
94             namespace: '_form_validator'
95             extensions:
96             dbic:
97             provider: 'Dancer2::Plugin::FormValidator::Extension::DBIC'
98             database: 'default' # DBIC database
99             ...
100             ...
101              
102             =head1 Dependencies
103              
104             This package requires L<Dancer2::Plugin::DBIC/https://metacpan.org/pod/Dancer2::Plugin::DBIC>.
105              
106             =head1 Validators
107              
108             =head3 exist
109              
110             exist:source,column
111              
112             The field under validation must exist within the given database source(table).
113              
114             =head3 unique
115              
116             unique:source,column
117              
118             The field under validation must not exist within the given database source(table).
119              
120             =head1 SOURCE CODE REPOSITORY
121              
122             L<https://github.com/AlexP007/dancer2-plugin-formvalidator-extension-dbic|https://github.com/AlexP007/dancer2-plugin-formvalidator-extension-dbic>.
123              
124             =head1 AUTHOR
125              
126             Alexander Panteleev <alexpan at cpan dot org>.
127              
128             =head1 LICENSE AND COPYRIGHT
129              
130             This software is copyright (c) 2022 by Alexander Panteleev.
131             This is free software; you can redistribute it and/or modify it under
132             the same terms as the Perl 5 programming language system itself.
133              
134             =cut