Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #########################PerlResponseHandler##########################
- package Marica::utf8;
- use strict ;
- use warnings ;
- use utf8 ;
- use Encode;
- use Apache2::Const -compile => qw(OK);
- #use Apache2::RequestRec () ;
- #use Apache2::RequestIO () ;
- sub handler {
- binmode(STDOUT, ":utf8");
- my $r = shift ;
- #récupérer les arguments
- my (%args, @args) ;
- my $req = Apache2::Request->new($r) ;
- #recherche des paramètres de la requête
- @args = $req->param ;
- for (@args) {
- $args{$_} = decode_utf8($req->param($_)) ;
- }
- $r->content_type('text/plain') ;
- print 'myparam : ' . $args{myparam} . ' : ' . utf8::is_utf8($args{myparam}) . "\n";
- my $string = 'lâàéè' ;
- print 'string : ' . $string . ' : ' . utf8::is_utf8($string) . "\n";
- my $dbh = DBI->connect_cached( "DBI:Pg:dbname=vv", 'vincent', undef, {
- PrintError => 1,
- RaiseError => 1,
- AutoCommit => 1,
- pg_bool_tf => 1 } )
- or die "Cannot connect to db: $?" ;
- $dbh->{pg_enable_utf8} = 1 ;
- my $sql = 'select \'' . $string . '\'' ;
- my $sth = $dbh->selectall_arrayref($sql) ;
- my $returned_value_1 = $sth->[0]->[0] ;
- print 'returned_value_1 : ' . $returned_value_1 . ' : ' . utf8::is_utf8($returned_value_1) . "\n";
- $sql = 'UPDATE bla set nom = ?' ;
- $dbh->do($sql, {}, ( $returned_value_1 ) ) ;
- $sql = 'SELECT nom FROM bla ' ;
- $sth = $dbh->selectall_arrayref($sql) ;
- my $returned_value_2 = $sth->[0]->[0] ;
- print 'returned_value_2 : ' . $returned_value_2 . ' : ' . utf8::is_utf8($returned_value_2) . "\n";
- $sql = 'UPDATE bla set nom = ?' ;
- $dbh->do($sql, {}, ( $args{myparam} ) ) ;
- $sql = 'SELECT nom FROM bla ' ;
- $sth = $dbh->selectall_arrayref($sql) ;
- my $returned_value_3 = $sth->[0]->[0] ;
- print 'returned_value_3 : ' . $returned_value_3 . ' : ' . utf8::is_utf8($returned_value_3) . "\n";
- return Apache2::Const::OK ;
- }
- 1;
- ######################################PerlOutputFilterHandler########################
- package Marica::reverse;
- use utf8;
- use Encode;
- use strict ;
- use warnings ;
- use base qw(Apache2::Filter);
- use Apache2::Const -compile => qw(OK);
- sub handler {
- my $f = shift;
- my $content = $f->ctx ;
- while ( $f->read(my $buffer) ) {
- my $warning = ( utf8::is_utf8($buffer) ) ? 'IS utf8' : 'NOT utf8' ;
- $content .= 'OutputFilterHandler $buffer ' . $warning . "\n";
- $content .= decode_utf8($buffer) ;
- }
- if ($f->seen_eos) {
- my $output_filter_string = 'àêôu € ';
- my $added_to_content = 'OutputFilterHandler $added_string ' . $output_filter_string . (( utf8::is_utf8($output_filter_string) ) ? 'IS utf8' : 'NOT utf8') . "\n" ;
- $content .= $added_to_content ;
- $f->print($content) ;
- } else {
- $f->ctx($content) if defined $content ;
- }
- return Apache2::Const::OK;
- }
- 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement