Advertisement
Guest User

Untitled

a guest
Aug 18th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. #########################PerlResponseHandler##########################
  2. package Marica::utf8;
  3.  
  4. use strict ;
  5. use warnings ;
  6.  
  7. use utf8 ;
  8. use Encode;
  9. use Apache2::Const -compile => qw(OK);
  10.  
  11. #use Apache2::RequestRec () ;
  12. #use Apache2::RequestIO () ;
  13.  
  14. sub handler {
  15.  
  16. binmode(STDOUT, ":utf8");
  17.  
  18. my $r = shift ;
  19.  
  20. #récupérer les arguments
  21. my (%args, @args) ;
  22.  
  23. my $req = Apache2::Request->new($r) ;
  24.  
  25. #recherche des paramètres de la requête
  26. @args = $req->param ;
  27.  
  28. for (@args) {
  29.  
  30. $args{$_} = decode_utf8($req->param($_)) ;
  31.  
  32. }
  33.  
  34. $r->content_type('text/plain') ;
  35.  
  36. print 'myparam : ' . $args{myparam} . ' : ' . utf8::is_utf8($args{myparam}) . "\n";
  37.  
  38. my $string = 'lâàéè' ;
  39.  
  40. print 'string : ' . $string . ' : ' . utf8::is_utf8($string) . "\n";
  41.  
  42. my $dbh = DBI->connect_cached( "DBI:Pg:dbname=vv", 'vincent', undef, {
  43. PrintError => 1,
  44. RaiseError => 1,
  45. AutoCommit => 1,
  46. pg_bool_tf => 1 } )
  47.  
  48. or die "Cannot connect to db: $?" ;
  49.  
  50. $dbh->{pg_enable_utf8} = 1 ;
  51.  
  52. my $sql = 'select \'' . $string . '\'' ;
  53.  
  54. my $sth = $dbh->selectall_arrayref($sql) ;
  55.  
  56. my $returned_value_1 = $sth->[0]->[0] ;
  57.  
  58. print 'returned_value_1 : ' . $returned_value_1 . ' : ' . utf8::is_utf8($returned_value_1) . "\n";
  59.  
  60. $sql = 'UPDATE bla set nom = ?' ;
  61.  
  62. $dbh->do($sql, {}, ( $returned_value_1 ) ) ;
  63.  
  64. $sql = 'SELECT nom FROM bla ' ;
  65.  
  66. $sth = $dbh->selectall_arrayref($sql) ;
  67.  
  68. my $returned_value_2 = $sth->[0]->[0] ;
  69.  
  70. print 'returned_value_2 : ' . $returned_value_2 . ' : ' . utf8::is_utf8($returned_value_2) . "\n";
  71.  
  72. $sql = 'UPDATE bla set nom = ?' ;
  73.  
  74. $dbh->do($sql, {}, ( $args{myparam} ) ) ;
  75.  
  76. $sql = 'SELECT nom FROM bla ' ;
  77.  
  78. $sth = $dbh->selectall_arrayref($sql) ;
  79.  
  80. my $returned_value_3 = $sth->[0]->[0] ;
  81.  
  82. print 'returned_value_3 : ' . $returned_value_3 . ' : ' . utf8::is_utf8($returned_value_3) . "\n";
  83.  
  84. return Apache2::Const::OK ;
  85.  
  86. }
  87.  
  88. 1;
  89.  
  90. ######################################PerlOutputFilterHandler########################
  91. package Marica::reverse;
  92. use utf8;
  93. use Encode;
  94. use strict ;
  95. use warnings ;
  96.  
  97. use base qw(Apache2::Filter);
  98.  
  99. use Apache2::Const -compile => qw(OK);
  100.  
  101. sub handler {
  102.  
  103. my $f = shift;
  104.  
  105. my $content = $f->ctx ;
  106.  
  107. while ( $f->read(my $buffer) ) {
  108.  
  109. my $warning = ( utf8::is_utf8($buffer) ) ? 'IS utf8' : 'NOT utf8' ;
  110.  
  111. $content .= 'OutputFilterHandler $buffer ' . $warning . "\n";
  112.  
  113. $content .= decode_utf8($buffer) ;
  114.  
  115. }
  116.  
  117. if ($f->seen_eos) {
  118.  
  119. my $output_filter_string = 'àêôu € ';
  120. my $added_to_content = 'OutputFilterHandler $added_string ' . $output_filter_string . (( utf8::is_utf8($output_filter_string) ) ? 'IS utf8' : 'NOT utf8') . "\n" ;
  121. $content .= $added_to_content ;
  122.  
  123. $f->print($content) ;
  124.  
  125. } else {
  126.  
  127. $f->ctx($content) if defined $content ;
  128.  
  129. }
  130.  
  131. return Apache2::Const::OK;
  132.  
  133. }
  134.  
  135. 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement