File Coverage

blib/lib/Data/Sah/Coerce/perl/To_array/From_str/comma_sep.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition 2 2 100.0
subroutine 5 5 100.0
pod 0 2 0.0
total 24 26 92.3


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