Commit | Line | Data |
---|---|---|
0478e945 KW |
1 | #! user/bin/perl -w |
2 | ||
3 | # t/JustPod01.t - check basics of Pod::Simple::JustPod | |
4 | ||
5 | BEGIN { | |
6 | chdir 't' if -d 't'; | |
7 | } | |
8 | ||
9 | use strict; | |
10 | use lib '../lib'; | |
11 | use Test::More tests => 2; | |
12 | ||
13 | use warnings; | |
14 | use utf8; | |
15 | ||
16 | use_ok('Pod::Simple::JustPod') or exit; | |
17 | ||
18 | my $parser = Pod::Simple::JustPod->new(); | |
19 | ||
20 | my $input; | |
21 | while ( <DATA> ) { $input .= $_ } | |
22 | ||
23 | my $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 | ||
30 | my $msg = "got expected output"; | |
31 | if ($output eq $input) { | |
32 | pass($msg); | |
33 | } | |
34 | elsif ($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 | } | |
55 | else { | |
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__ | |
70 | package utf8::all; | |
71 | use strict; | |
72 | use warnings; | |
73 | use 5.010; # state | |
74 | # ABSTRACT: turn on Unicode - all of it | |
75 | our $VERSION = '0.010'; # VERSION | |
76 | ||
77 | ||
78 | use Import::Into; | |
79 | use parent qw(Encode charnames utf8 open warnings feature); | |
80 | ||
81 | sub 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 | ||
104 | sub _encode_argv { | |
105 | $_ = Encode::decode('UTF-8', $_) for @ARGV; | |
106 | return; | |
107 | } | |
108 | ||
109 | sub _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 | ||
124 | 1; | |
125 | ||
126 | __END__ | |
127 | ||
128 | =pod | |
129 | ||
130 | =encoding utf-8 | |
131 | ||
132 | =head1 NAME | |
133 | ||
134 | utf8::all - turn on Unicode - all of it | |
135 | ||
136 | =head1 VERSION | |
137 | ||
138 | version 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 | ||
150 | L<utf8> allows you to write your Perl encoded in UTF-8. That means UTF-8 | |
151 | strings, variable names, and regular expressions. C<utf8::all> goes further, and | |
152 | makes C<@ARGV> encoded in UTF-8, and filehandles are opened with UTF-8 encoding | |
153 | turned on by default (including STDIN, STDOUT, STDERR), and charnames are | |
154 | imported so C<\N{...}> sequences can be used to compile Unicode characters based | |
155 | on names. If you I<don't> want UTF-8 for a particular filehandle, you'll have to | |
156 | set C<binmode $filehandle>. | |
157 | ||
158 | The pragma is lexically-scoped, so you can do the following if you had some | |
159 | reason 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 | ||
174 | If you use L<autodie>, which is a great idea, you need to use at least version | |
175 | B<2.12>, released on L<June 26, 2012|https://metacpan.org/source/PJF/autodie-2.12/Changes#L3>. | |
176 | Otherwise, autodie obliterates the IO layers set by the L<open> pragma. See | |
177 | L<RT #54777|https://rt.cpan.org/Ticket/Display.html?id=54777> and | |
178 | L<GH #7|https://github.com/doherty/utf8-all/issues/7>. | |
179 | ||
180 | =head1 AVAILABILITY | |
181 | ||
182 | The project homepage is L<http://metacpan.org/release/utf8-all/>. | |
183 | ||
184 | The latest version of this module is available from the Comprehensive Perl | |
185 | Archive Network (CPAN). Visit L<http://www.perl.com/CPAN/> to find a CPAN | |
186 | site near you, or see L<https://metacpan.org/module/utf8::all/>. | |
187 | ||
188 | =head1 SOURCE | |
189 | ||
190 | The development version is on github at L<http://github.com/doherty/utf8-all> | |
191 | and may be cloned from L<git://github.com/doherty/utf8-all.git> | |
192 | ||
193 | =head1 BUGS AND LIMITATIONS | |
194 | ||
195 | You can make new bug reports, and view existing ones, through the | |
196 | web interface at L<https://github.com/doherty/utf8-all/issues>. | |
197 | ||
198 | =head1 AUTHORS | |
199 | ||
200 | =over 4 | |
201 | ||
202 | =item * | |
203 | ||
204 | Michael Schwern <mschwern@cpan.org> | |
205 | ||
206 | =item * | |
207 | ||
208 | Mike Doherty <doherty@cpan.org> | |
209 | ||
210 | =back | |
211 | ||
212 | =head1 COPYRIGHT AND LICENSE | |
213 | ||
214 | This software is copyright (c) 2009 by Michael Schwern <mschwern@cpan.org>. | |
215 | ||
216 | This is free software; you can redistribute it and/or modify it under | |
217 | the same terms as the Perl 5 programming language system itself. | |
218 | ||
219 | =cut |