Poz/Builder.pm

filter: Statementstmt 85.7% 12 / 14 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 89.4% 17 / 19 CC 1 SCAR 0.6
CC
1
Cov
86%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Poz.pm ↑ Summary Poz/Types/string.pm »
1 package Poz::Builder;
2 11 ▶use 5.032;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use Poz::Types::null;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 0 ▶use Poz::Types::string;
Subroutine BEGIN: called CC=1 SCAR=2.6
7 use Poz::Types::number;
8 use Poz::Types::object;
9 use Poz::Types::array;
10 use Poz::Types::enum;
11 use Poz::Types::union;
12 use Poz::Types::is;
13  
14 sub new {
15 my ($class) = @_;
16 bless {
17 need_coerce => 0,
18 }, $class;
19 }
20  
21 sub coerce {
22 my ($self) = @_;
23 $self->{need_coerce} = 1;
24 return $self;
25 }
26  
27 sub null {
28 my ($self, $opts) = @_;
29 $opts = $opts || {};
30 return Poz::Types::null->new({
31 %{$opts},
32 need_coerce => $self->{need_coerce},
33 });
34 }
35  
36 sub string {
37 my ($self, $opts) = @_;
38 $opts = $opts || {};
39 return Poz::Types::string->new({
40 %{$opts},
41 need_coerce => $self->{need_coerce},
42 });
43 }
44  
45 sub date {
46 my ($self, $opts) = @_;
47 $opts = $opts || {};
48 return $self->string({invalid_type_error => 'Not a date', %$opts})->date;
49 }
50  
51 sub datetime {
52 my ($self, $opts) = @_;
53 $opts = $opts || {};
54 return $self->string({invalid_type_error => 'Not a datetime', %$opts})->datetime;
55 }
56  
57 sub number {
58 my ($self, $opts) = @_;
59 $opts = $opts || {};
60 return Poz::Types::number->new({
61 %{$opts},
62 need_coerce => $self->{need_coerce},
63 });
64 }
65  
66 sub object {
67 my ($self, $opts) = @_;
68 return Poz::Types::object->new({%$opts});
69 }
70  
71 sub array {
72 my ($self, $validator) = @_;
73 return Poz::Types::array->new($validator);
74 }
75  
76 sub enum {
77 my ($self, $opts) = @_;
78 return Poz::Types::enum->new($opts);
79 }
80  
81 sub union {
82 my ($self, @validators) = @_;
83 return Poz::Types::union->new(@validators);
84 }
85  
86 sub is {
87 my ($self, $isa) = @_;
88 return Poz::Types::is->new($isa);
89 }
90  
91 1;
92  
93 =head1 NAME
94  
95 Poz::Builder - A module for building Poz projects
96  
97 =head1 SYNOPSIS
98  
99 use Poz::Builder;
100 my $builder = Poz::Builder->new();
101 $builder->build();
102  
103 =head1 DESCRIPTION
104  
105 Poz::Builder is a module designed to facilitate the building and management of Poz projects. It provides methods to streamline the build process and ensure consistency across different environments.
106  
107 =head1 METHODS
108  
109 =head2 new
110  
111 my $builder = Poz::Builder->new();
112  
113 Creates a new Poz::Builder object.
114  
115 =head2 build
116  
117 $builder->build();
118  
119 Executes the build process for the Poz project.
120 =head2 coerce
121  
122 $builder->coerce();
123  
124 Enables coercion for the builder, which affects how types are handled.
125  
126 =head2 null
127  
128 my $null_type = $builder->null(\%opts);
129  
130 Creates a new null type with the given options.
131  
132 =head2 string
133  
134 my $string_type = $builder->string(\%opts);
135  
136 Creates a new string type with the given options.
137  
138 =head2 date
139  
140 my $date_type = $builder->date(\%opts);
141  
142 Creates a new date type with the given options. This is a specialized string type.
143  
144 =head2 number
145  
146 my $number_type = $builder->number(\%opts);
147  
148 Creates a new number type with the given options.
149  
150 =head2 object
151  
152 my $object_type = $builder->object(\%opts);
153  
154 Creates a new object type with the given options.
155  
156 =head2 array
157  
158 my $array_type = $builder->array($validator);
159  
160 Creates a new array type with the given validator.
161  
162 =head2 enum
163  
164 my $enum_type = $builder->enum(\%opts);
165  
166 Creates a new enum type with the given options.
167  
168 =head2 union
169  
170 my $union_type = $builder->union(@validators);
171  
172 Creates a new union type with the given validators.
173  
174 =head2 is
175  
176 my $is_type = $builder->is($isa);
177  
178 Creates a new is type with the given class.
179  
180 =head1 LICENSE
181  
182 Copyright (C) ytnobody.
183  
184 This library is free software; you can redistribute it and/or modify
185 it under the same terms as Perl itself.
186  
187 =head1 AUTHOR
188  
189 ytnobody E<lt>ytnobody@gmail.comE<gt>
190  
191 =cut
« Poz.pm ↑ Summary Poz/Types/string.pm »