File Coverage

blib/lib/Stancer/Core/Types/Bases.pm
Criterion Covered Total %
statement 26 26 100.0
branch n/a
condition n/a
subroutine 9 9 100.0
pod n/a
total 35 35 100.0


line stmt bran cond sub pod time code
1             package Stancer::Core::Types::Bases;
2              
3 63     63   383074 use 5.020;
  63         416  
4 63     63   412 use strict;
  63         182  
  63         1954  
5 63     63   349 use warnings;
  63         192  
  63         8646  
6              
7             # ABSTRACT: Internal bases types
8             our $VERSION = '1.0.3'; # VERSION
9              
10             our @EXPORT_OK = ();
11             our %EXPORT_TAGS = ('all' => \@EXPORT_OK);
12              
13 63     63   2642 use Stancer::Core::Types::Helper qw(error_message);
  63         172  
  63         4620  
14 63     63   3055 use Stancer::Exceptions::InvalidArgument;
  63         160  
  63         3421  
15 63     63   508 use List::Util qw(first);
  63         220  
  63         5176  
16 63     63   40219 use MooX::Types::MooseLike::Base qw();
  63         366097  
  63         2778  
17              
18 63     63   700 use namespace::clean;
  63         132  
  63         619  
19              
20 63     63   20108 use Exporter qw(import);
  63         676  
  63         34177  
21              
22             my @defs = ();
23              
24             push @defs, {
25             name => 'Bool',
26             subtype_of => 'Bool',
27             from => 'MooX::Types::MooseLike::Base',
28             test => sub { defined $_[0] },
29             message => error_message('%s is not a bool.'),
30             exception => 'Stancer::Exceptions::InvalidArgument',
31             };
32              
33             push @defs, {
34             name => 'Enum',
35             test => sub {
36             my ($value, @possible_values) = @_;
37              
38             return if not defined $value;
39             return first { $value eq $_ } @possible_values;
40             },
41             message => sub {
42             my ($value, @possible_values) = @_;
43              
44             my $message = 'Must be one of : %2$s. %1$s given'; ## no critic (RequireInterpolationOfMetachars)
45             my $possible = join ', ', map { q/"/ . $_ . q/"/ } @possible_values;
46              
47             return error_message($message)->($value, $possible);
48             },
49             exception => 'Stancer::Exceptions::InvalidArgument',
50             };
51              
52             push @defs, {
53             name => 'InstanceOf',
54             subtype_of => 'InstanceOf',
55             from => 'MooX::Types::MooseLike::Base',
56             test => sub { 1 },
57             exception => 'Stancer::Exceptions::InvalidArgument',
58             };
59              
60             push @defs, {
61             name => 'Maybe',
62             subtype_of => 'Maybe',
63             from => 'MooX::Types::MooseLike::Base',
64             test => sub { 1 },
65             parameterizable => sub { return if not defined $_[0]; $_[0] },
66             };
67              
68             push @defs, {
69             name => 'Str',
70             subtype_of => 'Str',
71             from => 'MooX::Types::MooseLike::Base',
72             test => sub { 1 },
73             message => error_message('%s is not a string.'),
74             exception => 'Stancer::Exceptions::InvalidArgument',
75             };
76              
77             for my $name (qw(ArrayRef HashRef Int Num)) {
78             push @defs, {
79             name => $name,
80             subtype_of => $name,
81             from => 'MooX::Types::MooseLike::Base',
82             test => sub { 1 }, # Just an alias
83             };
84             }
85              
86             Stancer::Core::Types::Helper::register_types(\@defs, __PACKAGE__);
87              
88             1;
89              
90             __END__
91              
92             =pod
93              
94             =encoding UTF-8
95              
96             =head1 NAME
97              
98             Stancer::Core::Types::Bases - Internal bases types
99              
100             =head1 VERSION
101              
102             version 1.0.3
103              
104             =head1 USAGE
105              
106             =head2 Logging
107              
108              
109              
110             We use the L<Log::Any> framework for logging events.
111             You may tell where it should log using any available L<Log::Any::Adapter> module.
112              
113             For example, to log everything to a file you just have to add a line to your script, like this:
114             #! /usr/bin/env perl
115             use Log::Any::Adapter (File => '/var/log/payment.log');
116             use Stancer::Core::Types::Bases;
117              
118             You must import C<Log::Any::Adapter> before our libraries, to initialize the logger instance before use.
119              
120             You can choose your log level on import directly:
121             use Log::Any::Adapter (File => '/var/log/payment.log', log_level => 'info');
122              
123             Read the L<Log::Any> documentation to know what other options you have.
124              
125             =cut
126              
127             =head1 SECURITY
128              
129             =over
130              
131             =item *
132              
133             Never, never, NEVER register a card or a bank account number in your database.
134              
135             =item *
136              
137             Always uses HTTPS in card/SEPA in communication.
138              
139             =item *
140              
141             Our API will never give you a complete card/SEPA number, only the last four digits.
142             If you need to keep track, use these last four digit.
143              
144             =back
145              
146             =cut
147              
148             =head1 BUGS
149              
150             Please report any bugs or feature requests on the bugtracker website
151             L<https://gitlab.com/wearestancer/library/lib-perl/-/issues> or by email to
152             L<bug-stancer@rt.cpan.org|mailto:bug-stancer@rt.cpan.org>.
153              
154             When submitting a bug or request, please include a test-file or a
155             patch to an existing test-file that illustrates the bug or desired
156             feature.
157              
158             =head1 AUTHOR
159              
160             Joel Da Silva <jdasilva@cpan.org>
161              
162             =head1 COPYRIGHT AND LICENSE
163              
164             This software is Copyright (c) 2018-2024 by Stancer / Iliad78.
165              
166             This is free software, licensed under:
167              
168             The Artistic License 2.0 (GPL Compatible)
169              
170             =cut