File Coverage

blib/lib/Data/Sah/Compiler/perl/TH.pm
Criterion Covered Total %
statement 36 36 100.0
branch n/a
condition 1 2 50.0
subroutine 7 7 100.0
pod 0 1 0.0
total 44 46 95.6


line stmt bran cond sub pod time code
1              
2             use 5.010;
3 22     22   8911 use strict;
  22         62  
4 22     22   112 use warnings;
  22         43  
  22         402  
5 22     22   103 use Log::ger;
  22         37  
  22         528  
6 22     22   114  
  22         36  
  22         154  
7             use Mo qw(build default);
8 22     22   4454 use Role::Tiny::With;
  22         42  
  22         107  
9 22     22   4934  
  22         39  
  22         6509  
10             extends 'Data::Sah::Compiler::Prog::TH';
11              
12             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
13             our $DATE = '2022-10-19'; # DATE
14             our $DIST = 'Data-Sah'; # DIST
15             our $VERSION = '0.914'; # VERSION
16              
17             my ($self, $cd, $indices_expr, $data_name, $data_term, $code_at_sub_begin) = @_;
18             my $c = $self->compiler;
19 103     103 0 272 my $cv = $cd->{cl_value};
20 103         233 my $dt = $cd->{data_term};
21 103         423  
22 103         211 local $cd->{_subdata_level} = $cd->{_subdata_level} + 1;
23              
24 103         290 $c->add_runtime_module($cd, 'List::Util');
25             my %iargs = %{$cd->{args}};
26 103         363 $iargs{outer_cd} = $cd;
27 103         296 $iargs{data_name} = $data_name;
  103         1164  
28 103         298 $iargs{data_term} = $data_term;
29 103         203 $iargs{schema} = $cv;
30 103         188 $iargs{schema_is_normalized} = 0;
31 103         180 $iargs{cache} = $cd->{args}{cache};
32 103         195 $iargs{indent_level}++;
33 103         256 $iargs{data_term_includes_topic_var} = 1;
34 103         148 my $icd = $c->compile(%iargs);
35 103         238 my @code = (
36 103         621 "!defined(List::Util::first(sub {", ($code_at_sub_begin // ''), "!(\n",
37             ($c->indent_str($cd),
38             "(\$_sahv_dpath->[-1] = \$_),\n") x !!$cd->{use_dpath},
39             $icd->{result}, "\n",
40             $c->indent_str($icd), ")}, ",
41 103   50     834 $indices_expr,
42             "))",
43             );
44             $c->add_ccl($cd, join("", @code), {subdata=>1});
45             }
46 103         1192  
47             1;
48             # ABSTRACT: Base class for perl type handlers
49              
50              
51             =pod
52              
53             =encoding UTF-8
54              
55             =head1 NAME
56              
57             Data::Sah::Compiler::perl::TH - Base class for perl type handlers
58              
59             =head1 VERSION
60              
61             This document describes version 0.914 of Data::Sah::Compiler::perl::TH (from Perl distribution Data-Sah), released on 2022-10-19.
62              
63             =for Pod::Coverage ^(compiler|clause_.+|gen_.+)$
64              
65             =head1 HOMEPAGE
66              
67             Please visit the project's homepage at L<https://metacpan.org/release/Data-Sah>.
68              
69             =head1 SOURCE
70              
71             Source repository is at L<https://github.com/perlancar/perl-Data-Sah>.
72              
73             =head1 AUTHOR
74              
75             perlancar <perlancar@cpan.org>
76              
77             =head1 CONTRIBUTING
78              
79              
80             To contribute, you can send patches by email/via RT, or send pull requests on
81             GitHub.
82              
83             Most of the time, you don't need to build the distribution yourself. You can
84             simply modify the code, then test via:
85              
86             % prove -l
87              
88             If you want to build the distribution (e.g. to try to install it locally on your
89             system), you can install L<Dist::Zilla>,
90             L<Dist::Zilla::PluginBundle::Author::PERLANCAR>,
91             L<Pod::Weaver::PluginBundle::Author::PERLANCAR>, and sometimes one or two other
92             Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond
93             that are considered a bug and can be reported to me.
94              
95             =head1 COPYRIGHT AND LICENSE
96              
97             This software is copyright (c) 2022, 2021, 2020, 2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012 by perlancar <perlancar@cpan.org>.
98              
99             This is free software; you can redistribute it and/or modify it under
100             the same terms as the Perl 5 programming language system itself.
101              
102             =head1 BUGS
103              
104             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Sah>
105              
106             When submitting a bug or request, please include a test-file or a
107             patch to an existing test-file that illustrates the bug or desired
108             feature.
109              
110             =cut