File Coverage

lib/Egg/Plugin/Charset.pm
Criterion Covered Total %
statement 6 19 31.5
branch 0 4 0.0
condition 0 11 0.0
subroutine 2 5 40.0
pod 1 1 100.0
total 9 40 22.5


line stmt bran cond sub pod time code
1             package Egg::Plugin::Charset;
2             #
3             # Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
4             #
5             # $Id: Charset.pm 337 2008-05-14 12:30:09Z lushe $
6             #
7 1     1   402 use strict;
  1         2  
  1         35  
8 1     1   5 use warnings;
  1         1  
  1         572  
9              
10             our $VERSION = '3.00';
11              
12             sub _setup {
13 0     0     my($e)= @_;
14 0           $e->mk_accessors('no_convert');
15 0           $e->next::method;
16             }
17             sub _output {
18 0     0     my $e= shift;
19 0   0       my $body= $e->get_convert_body || return $e->next::method;
20 0           $e->_convert_output_body($body);
21 0           $e->next::method;
22             }
23             sub get_convert_body {
24 0     0 1   my($e)= @_;
25 0           my $res= $e->response;
26             return (undef)
27 0 0 0       if ($e->no_convert or $e->request->is_head or $res->attachment);
      0        
28 0           my $type;
29             return (undef)
30 0 0 0       if ($type= $res->content_type and $type!~/^text\//i);
31 0           $res->body;
32             }
33              
34             1;
35              
36             __END__
37              
38             =head1 NAME
39              
40             Egg::Plugin::Charset - Base class for Charset plugin.
41              
42             =head1 SYNOPSIS
43              
44             use Egg qw/ Charset::UTF8 /;
45              
46             =head1 DESCRIPTION
47              
48             This module is a base class for the following subclasses.
49              
50             =over 4
51              
52             =item * L<Egg::Plugin::Charset::UTF8>
53              
54             =item * L<Egg::Plugin::Charset::EUC_JP>
55              
56             =item * L<Egg::Plugin::Charset::Shift_JIS>
57              
58             =back
59              
60             This module does interrupt to '_output'.
61             And, the character-code of contents set in $e->response->body is changed.
62              
63             The module with this method of '_convert_body' is made to make the subclass by
64             oneself, and processing that converts the character-code in this method is written.
65              
66             package Egg::Plugin::Charset::AnyCode;
67             use strict;
68             use ConvertAny;
69            
70             sub _setup {
71             my($e)= @_;
72             $e->config->{content_language}= 'ja';
73             $e->config->{charset_out}= "AnyCode";
74             $e->next::method;
75             }
76             sub _convert_body {
77             my $e = shift;
78             my $body = shift || return 0;
79             $$body= ConvertAny->convert($body); # $body is SCALAR reference.
80             }
81              
82             I think that it doesn't want to process this plug-in at times.
83              
84             =head1 METHODS
85              
86             =head2 no_convert ([BOOL])
87              
88             The processing of this plugin can temporarily be canceled for this case by
89             setting an effective value to $e-E<gt>no_convert.
90              
91             $e->no_convert(1);
92              
93             =head2 get_convert_body
94              
95             The contents sources to be converted are returned.
96              
97             Undefined is returned when $e-E<gt>no_convert or $e-E<gt>request-E<gt>is_head or
98             $e-E<gt>response-E<gt>attachment is effective.
99              
100             Undefined is returned if there is no $e-E<gt>response-E<gt>content_type in the
101             text system.
102              
103             =head1 SEE ALSO
104              
105             L<Egg::Release>,
106             L<Egg::Plugin::Charset::UTF8>,
107             L<Egg::Plugin::Charset::EUC_JP>,
108             L<Egg::Plugin::Charset::Shift_JIS>,
109              
110             =head1 AUTHOR
111              
112             Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
113              
114             =head1 COPYRIGHT AND LICENSE
115              
116             Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>.
117              
118             This library is free software; you can redistribute it and/or modify
119             it under the same terms as Perl itself, either Perl version 5.8.6 or,
120             at your option, any later version of Perl 5 you may have available.
121              
122             =cut
123