File Coverage

blib/lib/Template/Caribou/Utils.pm
Criterion Covered Total %
statement 52 52 100.0
branch 2 2 100.0
condition n/a
subroutine 20 20 100.0
pod n/a
total 74 74 100.0


line stmt bran cond sub pod time code
1             package Template::Caribou::Utils;
2             our $AUTHORITY = 'cpan:YANICK';
3             # ABSTRACT: internal utilities for Template::Caribou
4             $Template::Caribou::Utils::VERSION = '1.2.2';
5              
6 19     19   259748 use strict;
  19         66  
  19         845  
7 19     19   129 use warnings;
  19         69  
  19         1369  
8 19     19   108 no warnings qw/ uninitialized /;
  19         58  
  19         1080  
9              
10             BEGIN {
11 19     19   581 *::RAW = *::STDOUT;
12             }
13              
14 19     19   142 use parent 'Exporter::Tiny';
  19         40  
  19         249  
15              
16 19     19   123287 use experimental 'signatures';
  19         72800  
  19         159  
17              
18 19     19   3802 use Carp;
  19         73  
  19         3993  
19              
20              
21             package
22             Template::Caribou::String;
23              
24             use overload
25 122     122   4460 '""' => sub { return ${$_[0] } },
  122         672  
26 19     19   163 'eq' => sub { ${$_[0]} eq $_[1] };
  19     53   37  
  19         248  
  53         40370  
  53         218  
27              
28 117     117   1629 sub new { my ( $class, $string ) = @_; bless \$string, $class; }
  117         344  
29              
30              
31             package
32             Template::Caribou::Output;
33              
34 19     19   3454 use parent 'Tie::Handle';
  19         72  
  19         141  
35              
36 149     149   644 sub TIEHANDLE { return bless \my $i, shift; }
37              
38             sub escape {
39 19     19   56285 no warnings qw/ uninitialized/;
  19         45  
  19         4466  
40             @_ = map {
41 120     120   318 my $x = $_;
  120         201  
42 120         320 $x =~ s/&/&/g;
43 120         214 $x =~ s/</&lt;/g;
44 120         452 $x;
45             } @_;
46              
47 120 100       1081 return wantarray ? @_ : join '', @_;
48             }
49              
50 21     21   121 sub PRINT { shift; print ::RAW escape( @_ ) }
  21         65  
51              
52             package
53             Template::Caribou::OutputRaw;
54              
55 19     19   146 use parent 'Tie::Handle';
  19         36  
  19         116  
56              
57 149     149   461 sub TIEHANDLE { return bless \my $i, shift; }
58              
59             sub PRINT {
60 85     85   222 shift;
61 19     19   2665 no warnings qw/ uninitialized /;
  19         50  
  19         2050  
62 85         437 $Template::Caribou::OUTPUT .= join '', @_, $\;
63             }
64              
65             1;
66              
67             __END__
68              
69             =pod
70              
71             =encoding UTF-8
72              
73             =head1 NAME
74              
75             Template::Caribou::Utils - internal utilities for Template::Caribou
76              
77             =head1 VERSION
78              
79             version 1.2.2
80              
81             =head1 DESCRIPTION
82              
83             Used internally by L<Template::Caribou>. Nothing interesting
84             for end-users.
85              
86             =head1 AUTHOR
87              
88             Yanick Champoux <yanick@cpan.org>
89              
90             =head1 COPYRIGHT AND LICENSE
91              
92             This software is copyright (c) 2023 by Yanick Champoux.
93              
94             This is free software; you can redistribute it and/or modify it under
95             the same terms as the Perl 5 programming language system itself.
96              
97             =cut