This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Pod-Simple to CPAN version 3.36
[perl5.git] / cpan / Pod-Simple / t / JustPod01.t
CommitLineData
0478e945
KW
1#! user/bin/perl -w
2
3# t/JustPod01.t - check basics of Pod::Simple::JustPod
4
5BEGIN {
6 chdir 't' if -d 't';
7}
8
9use strict;
10use lib '../lib';
11use Test::More tests => 2;
12
13use warnings;
14use utf8;
15
16use_ok('Pod::Simple::JustPod') or exit;
17
18my $parser = Pod::Simple::JustPod->new();
19
20my $input;
21while ( <DATA> ) { $input .= $_ }
22
23my $output;
24$parser->output_string( \$output );
25$parser->parse_string_document( $input );
26
27# Strip off text before =pod in the input
28$input =~ s/^.*(=pod.*)$/$1/mgs;
29
30my $msg = "got expected output";
31if ($output eq $input) {
32 pass($msg);
33}
34elsif ($ENV{PERL_TEST_DIFF}) {
35 fail($msg);
36 require File::Temp;
37 my $orig_file = File::Temp->new();
38 local $/ = "\n";
39 chomp $input;
40 print $orig_file $input, "\n";
41 close $orig_file || die "Can't close orig_file: $!";
42
43 chomp $output;
44 my $parsed_file = File::Temp->new();
45 print $parsed_file $output, "\n";
46 close $parsed_file || die "Can't close parsed_file";
47
48 my $diff = File::Temp->new();
49 system("$ENV{PERL_TEST_DIFF} $orig_file $parsed_file > $diff");
50
51 open my $fh, "<", $diff || die "Can't open $diff";
52 my @diffs = <$fh>;
53 diag(@diffs);
54}
55else {
56 eval { require Text::Diff; };
57 if ($@) {
58 is($output, $input, $msg);
59 diag("Set environment variable PERL_TEST_DIFF=diff_tool or install"
60 . " Text::Diff to see just the differences.");
61 }
62 else {
63 fail($msg);
64 diag Text::Diff::diff(\$input, \$output, { STYLE => 'Unified' });
65 }
66}
67
68
69__DATA__
70package utf8::all;
71use strict;
72use warnings;
73use 5.010; # state
74# ABSTRACT: turn on Unicode - all of it
75our $VERSION = '0.010'; # VERSION
76
77
78use Import::Into;
79use parent qw(Encode charnames utf8 open warnings feature);
80
81sub import {
82 my $target = caller;
83 'utf8'->import::into($target);
84 'open'->import::into($target, qw{:encoding(UTF-8) :std});
85 'charnames'->import::into($target, qw{:full :short});
86 'warnings'->import::into($target, qw{FATAL utf8});
87 'feature'->import::into($target, qw{unicode_strings}) if $^V >= v5.11.0;
88 'feature'->import::into($target, qw{unicode_eval fc}) if $^V >= v5.16.0;
89
90 {
91 no strict qw(refs); ## no critic (TestingAndDebugging::ProhibitNoStrict)
92 *{$target . '::readdir'} = \&_utf8_readdir;
93 }
94
95 # utf8 in @ARGV
96 state $have_encoded_argv = 0;
97 _encode_argv() unless $have_encoded_argv++;
98
99 $^H{'utf8::all'} = 1;
100
101 return;
102}
103
104sub _encode_argv {
105 $_ = Encode::decode('UTF-8', $_) for @ARGV;
106 return;
107}
108
109sub _utf8_readdir(*) { ## no critic (Subroutines::ProhibitSubroutinePrototypes)
110 my $handle = shift;
111 if (wantarray) {
112 my @all_files = CORE::readdir($handle);
113 $_ = Encode::decode('UTF-8', $_) for @all_files;
114 return @all_files;
115 }
116 else {
117 my $next_file = CORE::readdir($handle);
118 $next_file = Encode::decode('UTF-8', $next_file);
119 return $next_file;
120 }
121}
122
123
1241;
125
126__END__
127
128=pod
129
130=encoding utf-8
131
132=head1 NAME
133
134utf8::all - turn on Unicode - all of it
135
136=head1 VERSION
137
138version 0.010
139
140=head1 SYNOPSIS
141
142 use utf8::all; # Turn on UTF-8. All of it.
143
144 open my $in, '<', 'contains-utf8'; # UTF-8 already turned on here
145 print length 'føø bār'; # 7 UTF-8 characters
146 my $utf8_arg = shift @ARGV; # @ARGV is UTF-8 too!
147
148=head1 DESCRIPTION
149
150L<utf8> allows you to write your Perl encoded in UTF-8. That means UTF-8
151strings, variable names, and regular expressions. C<utf8::all> goes further, and
152makes C<@ARGV> encoded in UTF-8, and filehandles are opened with UTF-8 encoding
153turned on by default (including STDIN, STDOUT, STDERR), and charnames are
154imported so C<\N{...}> sequences can be used to compile Unicode characters based
155on names. If you I<don't> want UTF-8 for a particular filehandle, you'll have to
156set C<binmode $filehandle>.
157
158The pragma is lexically-scoped, so you can do the following if you had some
159reason to:
160
161 {
162 use utf8::all;
163 open my $out, '>', 'outfile';
164 my $utf8_str = 'føø bār';
165 print length $utf8_str, "\n"; # 7
166 print $out $utf8_str; # out as utf8
167 }
168 open my $in, '<', 'outfile'; # in as raw
169 my $text = do { local $/; <$in>};
170 print length $text, "\n"; # 10, not 7!
171
172=head1 INTERACTION WITH AUTODIE
173
174If you use L<autodie>, which is a great idea, you need to use at least version
175B<2.12>, released on L<June 26, 2012|https://metacpan.org/source/PJF/autodie-2.12/Changes#L3>.
176Otherwise, autodie obliterates the IO layers set by the L<open> pragma. See
177L<RT #54777|https://rt.cpan.org/Ticket/Display.html?id=54777> and
178L<GH #7|https://github.com/doherty/utf8-all/issues/7>.
179
180=head1 AVAILABILITY
181
182The project homepage is L<http://metacpan.org/release/utf8-all/>.
183
184The latest version of this module is available from the Comprehensive Perl
185Archive Network (CPAN). Visit L<http://www.perl.com/CPAN/> to find a CPAN
186site near you, or see L<https://metacpan.org/module/utf8::all/>.
187
188=head1 SOURCE
189
190The development version is on github at L<http://github.com/doherty/utf8-all>
191and may be cloned from L<git://github.com/doherty/utf8-all.git>
192
193=head1 BUGS AND LIMITATIONS
194
195You can make new bug reports, and view existing ones, through the
196web interface at L<https://github.com/doherty/utf8-all/issues>.
197
198=head1 AUTHORS
199
200=over 4
201
202=item *
203
204Michael Schwern <mschwern@cpan.org>
205
206=item *
207
208Mike Doherty <doherty@cpan.org>
209
210=back
211
212=head1 COPYRIGHT AND LICENSE
213
214This software is copyright (c) 2009 by Michael Schwern <mschwern@cpan.org>.
215
216This is free software; you can redistribute it and/or modify it under
217the same terms as the Perl 5 programming language system itself.
218
219=cut