| 1 | package Poz::Types::scalar; | ||||||||||
| 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 parent 'Poz::Types'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 0 | ▶ | sub coerce { | ||||||||
|
Subroutine
coerce: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 8 | 0 | my ($self, $value) = @_; | |||||||||
| 9 | 0 | return $value; | |||||||||
| 10 | } | ||||||||||
| 11 | |||||||||||
| 12 | 0 | ▶ | sub default { | ||||||||
|
Subroutine
default: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 13 | 0 | my ($self, $default) = @_; | |||||||||
| 14 | 0 | ▶ | push @{$self->{transform}}, sub { | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 15 | 0 | my ($self, $value) = @_; | |||||||||
| 16 | 0 | ▶ | return $value if defined $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 0 | ▶ | return ref($default) eq "CODE" ? $default->($self) : $default; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | 0 | }; | |||||||||
| 19 | 0 | return $self; | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | 0 | ▶ | sub nullable { | ||||||||
|
Subroutine
nullable: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 23 | 0 | my ($self) = @_; | |||||||||
| 24 | 0 | ▶ | unshift @{$self->{rules}}, sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 25 | 0 | my ($self, $value) = @_; | |||||||||
| 26 | 0 | ▶ | return bless [], "Poz::Result::ShortCircuit" unless defined $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 0 | return; | |||||||||
| 28 | 0 | }; | |||||||||
| 29 | 0 | return $self; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | sub optional { | ||||||||
|
Subroutine
optional: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 33 | 0 | my ($self) = @_; | |||||||||
| 34 | 0 | ▶ | unshift @{$self->{rules}}, sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 35 | 0 | my ($self, $value) = @_; | |||||||||
| 36 | 0 | ▶ | return bless [], "Poz::Result::ShortCircuit" unless defined $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | return; | |||||||||
| 38 | 0 | }; | |||||||||
| 39 | 0 | return $self; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 11 | 1; | |||||||||
| 43 | |||||||||||
| 44 | =head1 NAME | ||||||||||
| 45 | |||||||||||
| 46 | Poz::Types::scalar - Scalar type handling for Poz framework | ||||||||||
| 47 | |||||||||||
| 48 | =head1 SYNOPSIS | ||||||||||
| 49 | |||||||||||
| 50 | use Poz::Types::scalar; | ||||||||||
| 51 | |||||||||||
| 52 | my $scalar_type = Poz::Types::scalar->new(); | ||||||||||
| 53 | $scalar_type->default('default_value'); | ||||||||||
| 54 | $scalar_type->nullable(); | ||||||||||
| 55 | $scalar_type->optional(); | ||||||||||
| 56 | |||||||||||
| 57 | =head1 DESCRIPTION | ||||||||||
| 58 | |||||||||||
| 59 | Poz::Types::scalar provides methods to handle scalar types within the Poz framework. It allows setting default values, marking values as nullable or optional, and coercing values. | ||||||||||
| 60 | |||||||||||
| 61 | =head1 METHODS | ||||||||||
| 62 | |||||||||||
| 63 | =head2 coerce | ||||||||||
| 64 | |||||||||||
| 65 | $scalar_type->coerce($value); | ||||||||||
| 66 | |||||||||||
| 67 | Returns the given value without modification. This method is used to coerce values into the desired type. | ||||||||||
| 68 | |||||||||||
| 69 | =head2 default | ||||||||||
| 70 | |||||||||||
| 71 | $scalar_type->default($default_value); | ||||||||||
| 72 | |||||||||||
| 73 | Sets a default value for the scalar type. If the value is undefined, the default value will be used. The default value can be a scalar or a code reference. | ||||||||||
| 74 | |||||||||||
| 75 | =head2 nullable | ||||||||||
| 76 | |||||||||||
| 77 | $scalar_type->nullable(); | ||||||||||
| 78 | |||||||||||
| 79 | Marks the scalar type as nullable. If the value is undefined, it will short-circuit and return without further processing. | ||||||||||
| 80 | |||||||||||
| 81 | =head2 optional | ||||||||||
| 82 | |||||||||||
| 83 | $scalar_type->optional(); | ||||||||||
| 84 | |||||||||||
| 85 | Marks the scalar type as optional. If the value is undefined, it will short-circuit and return without further processing. | ||||||||||
| 86 | |||||||||||
| 87 | =head1 LICENSE | ||||||||||
| 88 | |||||||||||
| 89 | Copyright (C) ytnobody. | ||||||||||
| 90 | |||||||||||
| 91 | This library is free software; you can redistribute it and/or modify | ||||||||||
| 92 | it under the same terms as Perl itself. | ||||||||||
| 93 | |||||||||||
| 94 | =head1 AUTHOR | ||||||||||
| 95 | |||||||||||
| 96 | ytnobody E<lt>ytnobody@gmail.comE<gt> | ||||||||||
| 97 | |||||||||||
| 98 | =cut | ||||||||||