@@ -383,7 +383,7 @@ sub _init {
383383
384384 my $handle = delete $props {handle };
385385 my ( %valid_props , @valid_props );
386- @valid_props = qw( collect_pod inc ) ;
386+ @valid_props = qw( collect_pod inc decode_pod ) ;
387387 @valid_props {@valid_props } = delete ( @props {@valid_props } );
388388 warn " Unknown properties: @{[keys %props ]}\n " if scalar ( %props );
389389
@@ -542,6 +542,7 @@ sub _parse_fh {
542542 my $pod_sect = ' ' ;
543543 my $pod_data = ' ' ;
544544 my $in_end = 0;
545+ my $encoding = ' ' ;
545546
546547 while (defined ( my $line = <$fh > )) {
547548 my $line_num = $. ;
@@ -570,6 +571,9 @@ sub _parse_fh {
570571 $pod_sect = $1 ;
571572 }
572573 elsif ( $self -> {collect_pod } ) {
574+ if ( $self -> {decode_pod } && $line =~ / ^=encoding ([\w -]+)/ ) {
575+ $encoding = $1 ;
576+ }
573577 $pod_data .= " $line \n " ;
574578 }
575579 next ;
@@ -658,6 +662,11 @@ sub _parse_fh {
658662 $pod {$pod_sect } = $pod_data ;
659663 }
660664
665+ if ( $self -> {decode_pod } && $encoding ) {
666+ require Encode;
667+ $_ = Encode::decode( $encoding , $_ ) for values %pod ;
668+ }
669+
661670 $self -> {versions } = \%vers ;
662671 $self -> {packages } = \@packages ;
663672 $self -> {pod } = \%pod ;
@@ -854,7 +863,7 @@ in the CPAN toolchain.
854863
855864=head1 CLASS METHODS
856865
857- =head2 C<< new_from_file($filename, collect_pod => 1) >>
866+ =head2 C<< new_from_file($filename, collect_pod => 1, decode_pod => 1 ) >>
858867
859868Constructs a C<Module::Metadata > object given the path to a file. Returns
860869undef if the filename does not exist.
@@ -867,7 +876,10 @@ If the file begins by an UTF-8, UTF-16BE or UTF-16LE byte-order mark, then
867876it is skipped before processing, and the content of the file is also decoded
868877appropriately starting from perl 5.8.
869878
870- =head2 C<< new_from_handle($handle, $filename, collect_pod => 1) >>
879+ Alternatively, if C<decode_pod > is set, it will decode the collected pod
880+ sections according to the C<=encoding > declaration.
881+
882+ =head2 C<< new_from_handle($handle, $filename, collect_pod => 1, decode_pod => 1) >>
871883
872884This works just like C<new_from_file > , except that a handle can be provided
873885as the first argument.
@@ -880,15 +892,15 @@ mandatory or undef will be returned.
880892You are responsible for setting the decoding layers on C<$handle > if
881893required.
882894
883- =head2 C<< new_from_module($module, collect_pod => 1, inc => \@dirs) >>
895+ =head2 C<< new_from_module($module, collect_pod => 1, inc => \@dirs, decode_pod => 1 ) >>
884896
885897Constructs a C<Module::Metadata > object given a module or package name.
886898Returns undef if the module cannot be found.
887899
888- In addition to accepting the C<collect_pod > argument as described above,
889- this method accepts a C<inc > argument which is a reference to an array of
890- directories to search for the module. If none are given, the default is
891- @INC.
900+ In addition to accepting the C<collect_pod > and C< decode_pod > arguments as
901+ described above, this method accepts a C<inc > argument which is a reference to
902+ an array of directories to search for the module. If none are given, the
903+ default is @INC.
892904
893905If the file that contains the module begins by an UTF-8, UTF-16BE or
894906UTF-16LE byte-order mark, then it is skipped before processing, and the
0 commit comments