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