File Coverage

blib/lib/Data/Sah/Coerce/perl/To_str/From_str/trim.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 20 22 90.9


line stmt bran cond sub pod time code
1             package Data::Sah::Coerce::perl::To_str::From_str::trim;
2              
3             # AUTHOR
4             our $DATE = '2019-11-28'; # DATE
5             our $DIST = 'Data-Sah-Coerce-perl-To_str-From_str-trim'; # DIST
6             our $VERSION = '0.006'; # VERSION
7              
8 1     1   1652 use 5.010001;
  1         3  
9 1     1   4 use strict;
  1         2  
  1         17  
10 1     1   4 use warnings;
  1         2  
  1         138  
11              
12             sub meta {
13             +{
14 1     1 0 12 v => 4,
15             summary => 'Trim whitespaces at the beginning and end of string',
16             prio => 50,
17             precludes => ['From_str::ltrim', 'From_str::rtrim'],
18             };
19             }
20              
21             sub coerce {
22 1     1 0 13 my %args = @_;
23              
24 1         2 my $dt = $args{data_term};
25              
26 1         2 my $res = {};
27              
28 1         3 $res->{expr_match} = "!ref($dt)";
29 1         3 $res->{expr_coerce} = join(
30             "",
31             "do { my \$res = $dt; \$res =~ s/\\A\\s+//s; \$res =~ s/\\s+\\z//s; \$res }",
32             );
33              
34 1         3 $res;
35             }
36              
37             1;
38             # ABSTRACT: Trim whitespaces at the beginning and end of string
39              
40             __END__
41              
42             =pod
43              
44             =encoding UTF-8
45              
46             =head1 NAME
47              
48             Data::Sah::Coerce::perl::To_str::From_str::trim - Trim whitespaces at the beginning and end of string
49              
50             =head1 VERSION
51              
52             This document describes version 0.006 of Data::Sah::Coerce::perl::To_str::From_str::trim (from Perl distribution Data-Sah-Coerce-perl-To_str-From_str-trim), released on 2019-11-28.
53              
54             =head1 SYNOPSIS
55              
56             To use in a Sah schema:
57              
58             ["str",{"x.perl.coerce_rules"=>["From_str::trim"]}]
59              
60             =for Pod::Coverage ^(meta|coerce)$
61              
62             =head1 HOMEPAGE
63              
64             Please visit the project's homepage at L<https://metacpan.org/release/Data-Sah-Coerce-perl-To_str-From_str-trim>.
65              
66             =head1 SOURCE
67              
68             Source repository is at L<https://github.com/perlancar/perl-Data-Sah-Coerce-perl-To_str-From_str-trim>.
69              
70             =head1 BUGS
71              
72             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Sah-Coerce-perl-To_str-From_str-trim>
73              
74             When submitting a bug or request, please include a test-file or a
75             patch to an existing test-file that illustrates the bug or desired
76             feature.
77              
78             =head1 AUTHOR
79              
80             perlancar <perlancar@cpan.org>
81              
82             =head1 COPYRIGHT AND LICENSE
83              
84             This software is copyright (c) 2019, 2018 by perlancar@cpan.org.
85              
86             This is free software; you can redistribute it and/or modify it under
87             the same terms as the Perl 5 programming language system itself.
88              
89             =cut