File Coverage

blib/lib/Stancer/Core/Types/Network.pm
Criterion Covered Total %
statement 32 32 100.0
branch n/a
condition n/a
subroutine 11 11 100.0
pod n/a
total 43 43 100.0


line stmt bran cond sub pod time code
1             package Stancer::Core::Types::Network;
2              
3 61     61   398819 use 5.020;
  61         240  
4 61     61   390 use strict;
  61         146  
  61         1857  
5 61     61   349 use warnings;
  61         241  
  61         8600  
6              
7             # ABSTRACT: Internal network types
8             our $VERSION = '1.0.3'; # VERSION
9              
10             our @EXPORT_OK = ();
11             our %EXPORT_TAGS = ('all' => \@EXPORT_OK);
12              
13 61     61   1841 use Stancer::Core::Types::Helper qw(error_message);
  61         149  
  61         4751  
14 61     61   32384 use Stancer::Exceptions::InvalidIpAddress;
  61         277  
  61         2859  
15 61     61   32874 use Stancer::Exceptions::InvalidPort;
  61         259  
  61         2867  
16 61     61   32125 use Stancer::Exceptions::InvalidUrl;
  61         295  
  61         2771  
17 61     61   1700 use MooX::Types::MooseLike::Base qw();
  61         13389  
  61         1857  
18 61     61   40134 use Socket qw(AF_INET AF_INET6 inet_pton);
  61         313803  
  61         16259  
19              
20 61     61   558 use namespace::clean;
  61         127  
  61         510  
21              
22 61     61   22194 use Exporter qw(import);
  61         143  
  61         18598  
23              
24             my @defs = ();
25              
26             push @defs, {
27             name => 'IpAddress',
28             test => sub {
29             my $value = shift;
30              
31             return 0 if not defined $value;
32             return 1 if defined inet_pton(AF_INET, $value);
33             return 1 if defined inet_pton(AF_INET6, $value);
34             return 0;
35             },
36             message => error_message('%s is not a valid IP address.'),
37             exception => 'Stancer::Exceptions::InvalidIpAddress',
38             };
39              
40             push @defs, {
41             name => 'Port',
42             subtype_of => 'Int',
43             from => 'MooX::Types::MooseLike::Base',
44             test => sub { $_[0] > 0 && $_[0] <= 65_535 },
45             message => error_message('Must be at less than 65535, %s given.'),
46             exception => 'Stancer::Exceptions::InvalidPort',
47             };
48              
49             push @defs, {
50             name => 'Url',
51             test => sub {
52             my $value = shift;
53              
54             return 0 if not defined $value;
55             return $value =~ /^https:\/\//smx;
56             },
57             message => error_message('%s is not a valid HTTPS url.'),
58             exception => 'Stancer::Exceptions::InvalidUrl',
59             };
60              
61             Stancer::Core::Types::Helper::register_types(\@defs, __PACKAGE__);
62              
63             1;
64              
65             __END__
66              
67             =pod
68              
69             =encoding UTF-8
70              
71             =head1 NAME
72              
73             Stancer::Core::Types::Network - Internal network types
74              
75             =head1 VERSION
76              
77             version 1.0.3
78              
79             =head1 USAGE
80              
81             =head2 Logging
82              
83              
84              
85             We use the L<Log::Any> framework for logging events.
86             You may tell where it should log using any available L<Log::Any::Adapter> module.
87              
88             For example, to log everything to a file you just have to add a line to your script, like this:
89             #! /usr/bin/env perl
90             use Log::Any::Adapter (File => '/var/log/payment.log');
91             use Stancer::Core::Types::Network;
92              
93             You must import C<Log::Any::Adapter> before our libraries, to initialize the logger instance before use.
94              
95             You can choose your log level on import directly:
96             use Log::Any::Adapter (File => '/var/log/payment.log', log_level => 'info');
97              
98             Read the L<Log::Any> documentation to know what other options you have.
99              
100             =cut
101              
102             =head1 SECURITY
103              
104             =over
105              
106             =item *
107              
108             Never, never, NEVER register a card or a bank account number in your database.
109              
110             =item *
111              
112             Always uses HTTPS in card/SEPA in communication.
113              
114             =item *
115              
116             Our API will never give you a complete card/SEPA number, only the last four digits.
117             If you need to keep track, use these last four digit.
118              
119             =back
120              
121             =cut
122              
123             =head1 BUGS
124              
125             Please report any bugs or feature requests on the bugtracker website
126             L<https://gitlab.com/wearestancer/library/lib-perl/-/issues> or by email to
127             L<bug-stancer@rt.cpan.org|mailto:bug-stancer@rt.cpan.org>.
128              
129             When submitting a bug or request, please include a test-file or a
130             patch to an existing test-file that illustrates the bug or desired
131             feature.
132              
133             =head1 AUTHOR
134              
135             Joel Da Silva <jdasilva@cpan.org>
136              
137             =head1 COPYRIGHT AND LICENSE
138              
139             This software is Copyright (c) 2018-2024 by Stancer / Iliad78.
140              
141             This is free software, licensed under:
142              
143             The Artistic License 2.0 (GPL Compatible)
144              
145             =cut