Devel-StringInfo

 view release on metacpan or  search on metacpan

lib/Devel/StringInfo.pm  view on Meta::CPAN

	auto_deref => 1,
	default    => sub { [] },
);

has include_value_info => (
	isa => "Bool",
	is  => "rw",
	default => 0,
);

has include_decoded => (
	isa => "Bool",
	is  => "rw",
	default => 1,
);

has include_hex => (
	isa => "Bool",
	is => "rw",
	default => 0,
);

lib/Devel/StringInfo.pm  view on Meta::CPAN

		octet_length => length($string),
		( utf8::valid($string)
			? $self->gather_data_utf8_octets($string)
			: $self->gather_data_non_utf8_octets($string) ),
	);
}

sub gather_data_utf8_octets {
	my ( $self, $string ) = @_;

	my $decoded = decode( utf8 => $string );
	
	my $guessed = sorted_hash $self->gather_data_encoding_info($string);

	if ( ($guessed->{guessed_encoding}||'') eq 'utf8' ) {
		return (
			valid_utf8  => 1,
			( $self->include_decoded ? $self->gather_data_decoded( $decoded, $string ) : () ),,
		);
	} else {
		return (
			valid_utf8 => 1,
			( $self->include_decoded ? (
				as_utf8    => sorted_hash($self->gather_data_decoded( $decoded, $string ) ),
				as_guess   => $guessed,
			) : () ),
		);
	}
}

sub gather_data_non_utf8_octets {
	my ( $self, $string ) = @_;

	return (

lib/Devel/StringInfo.pm  view on Meta::CPAN

}

sub gather_data_encoding_info {
	my ( $self, $string ) = @_;

	return unless $self->guess_encoding;

	my $decoder = Encode::Guess::guess_encoding( $string, $self->encoding_suspects );

	if ( ref $decoder ) {
		my $decoded = $decoder->decode($string);

		return (
			guessed_encoding => $decoder->name,
			( $self->include_decoded ? $self->gather_data_decoded( $decoded, $string ) : () ),
		);
	} else {
		return (
			guess_error => $decoder,
		);
	}
}

sub gather_data_decoded {
	my ( $self, $decoded, $string ) = @_;

	if ( $string ne $decoded ) {
		return (
			decoded_is_same => 0,
			decoded => {
				string => $decoded,
				$self->gather_data($decoded),
			}
		);
	} else {
		return (
			decoded_is_same => 1,
		);
	}
}

__PACKAGE__;

__END__

=pod

lib/Devel/StringInfo.pm  view on Meta::CPAN

=item encoding_suspects

The list of suspect encodings. See L<Encode::Guess>. Defaults to the empty
list, which is a special case for L<Encode::Guess>.

=item include_value_info

Include some information about the string value (does it contain C<0x00> chars,
is it alphanumeric, does it have newlines, etc).

=item include_decoded

Whether to include a recursive dump of the decoded versions of a non unicode
string.

=item include_hex

Whether to include a L<Data::HexDump::XXD> dump in C<dump_info>.

=item include_raw

Whether to include a simple interpolation of the string in C<dump_info>.



( run in 0.241 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )