File Coverage

blib/lib/Data/Sah/Compiler/TextResultRole.pm
Criterion Covered Total %
statement 28 37 75.6
branch 3 4 75.0
condition 7 15 46.6
subroutine 8 11 72.7
pod 5 5 100.0
total 51 72 70.8


line stmt bran cond sub pod time code
1              
2             use 5.010;
3 24     24   10052 use strict;
  24         81  
4 24     24   117 use warnings;
  24         41  
  24         462  
5 24     24   107  
  24         42  
  24         698  
6             use Mo qw(default);
7 24     24   108 use Role::Tiny;
  24         44  
  24         117  
8 24     24   3972  
  24         45  
  24         123  
9             # can be changed to tab, for example
10             has indent_character => (is => 'rw', default => sub {''});
11              
12             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
13             our $DATE = '2022-08-20'; # DATE
14             our $DIST = 'Data-Sah'; # DIST
15             our $VERSION = '0.912'; # VERSION
16              
17             my ($self, $cd, @args) = @_;
18              
19 0     0 1 0 $cd->{result} //= [];
20             push @{ $cd->{result} }, $self->indent($cd, join("", @args));
21 0   0     0 $self;
22 0         0 }
  0         0  
23 0         0  
24             # BEGIN COPIED FROM String::Indent
25             my ($indent, $str, $opts) = @_;
26             $opts //= {};
27              
28 5199     5199   44899 my $ibl = $opts->{indent_blank_lines} // 1;
29 5199   50     20434 my $fli = $opts->{first_line_indent} // $indent;
30             my $sli = $opts->{subsequent_lines_indent} // $indent;
31 5199   50     17175 #say "D:ibl=<$ibl>, fli=<$fli>, sli=<$sli>";
32 5199   66     15158  
33 5199   66     14468 my $i = 0;
34             $str =~ s/^([^\r\n]?)/$i++; !$ibl && !$1 ? "$1" : $i==1 ? "$fli$1" : "$sli$1"/egm;
35             $str;
36 5199         7069 }
37 5199 100 33     24473 # END COPIED FROM String::Indent
  70971 50       81559  
  70971         230708  
38 5199         37909  
39             my ($self, $cd, $str) = @_;
40             _indent(
41             $self->indent_character x $cd->{indent_level},
42             $str,
43 5199     5199 1 12718 );
44             }
45              
46 5199         15017 my ($self, $cd) = @_;
47             $cd->{indent_level}++;
48             }
49              
50             my ($self, $cd) = @_;
51 0     0 1 0 $cd->{indent_level}--;
52 0         0 }
53              
54             my ($self, $cd) = @_;
55             $self->indent_character x $cd->{indent_level};
56 0     0 1 0 }
57 0         0  
58             1;
59             # ABSTRACT: Role for compilers that produce text result (array of lines)
60              
61 566     566 1 3447  
62 566         1038 =pod
63              
64             =encoding UTF-8
65              
66             =head1 NAME
67              
68             Data::Sah::Compiler::TextResultRole - Role for compilers that produce text result (array of lines)
69              
70             =head1 VERSION
71              
72             This document describes version 0.912 of Data::Sah::Compiler::TextResultRole (from Perl distribution Data-Sah), released on 2022-08-20.
73              
74             =head1 ATTRIBUTES
75              
76             =head2 indent_character => STR
77              
78             =head1 METHODS
79              
80             =head2 $c->add_result($cd, @arg)
81              
82             Append result to C<< $cd->{result} >>. Will use C<< $cd->{indent_level} >> to
83             indent the line. Used by compiler; users normally do not need this.
84              
85             =head2 $c->inc_indent($cd)
86              
87             Increase indent level. This is done by increasing C<< $cd->{indent_level} >> by
88             1.
89              
90             =head2 $c->dec_indent($cd)
91              
92             Decrease indent level. This is done by decreasing C<< $cd->{indent_level} >> by
93             1.
94              
95             =head2 $c->indent_str($cd)
96              
97             Shortcut for C<< $c->indent_character x $cd->{indent_level} >>.
98              
99             =head2 $c->indent($cd, $str) => STR
100              
101             Indent each line in $str with indent_str and return the result.
102              
103             =head1 HOMEPAGE
104              
105             Please visit the project's homepage at L<https://metacpan.org/release/Data-Sah>.
106              
107             =head1 SOURCE
108              
109             Source repository is at L<https://github.com/perlancar/perl-Data-Sah>.
110              
111             =head1 AUTHOR
112              
113             perlancar <perlancar@cpan.org>
114              
115             =head1 CONTRIBUTING
116              
117              
118             To contribute, you can send patches by email/via RT, or send pull requests on
119             GitHub.
120              
121             Most of the time, you don't need to build the distribution yourself. You can
122             simply modify the code, then test via:
123              
124             % prove -l
125              
126             If you want to build the distribution (e.g. to try to install it locally on your
127             system), you can install L<Dist::Zilla>,
128             L<Dist::Zilla::PluginBundle::Author::PERLANCAR>,
129             L<Pod::Weaver::PluginBundle::Author::PERLANCAR>, and sometimes one or two other
130             Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond
131             that are considered a bug and can be reported to me.
132              
133             =head1 COPYRIGHT AND LICENSE
134              
135             This software is copyright (c) 2022, 2021, 2020, 2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012 by perlancar <perlancar@cpan.org>.
136              
137             This is free software; you can redistribute it and/or modify it under
138             the same terms as the Perl 5 programming language system itself.
139              
140             =head1 BUGS
141              
142             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Sah>
143              
144             When submitting a bug or request, please include a test-file or a
145             patch to an existing test-file that illustrates the bug or desired
146             feature.
147              
148             =cut