File: Perl56Compat.pm

package info (click to toggle)
libtype-tiny-perl 1.012001-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,432 kB
  • sloc: perl: 12,688; makefile: 2; sh: 1
file content (84 lines) | stat: -rw-r--r-- 1,918 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package Devel::TypeTiny::Perl56Compat;

use 5.006;
use strict;
use warnings;

our $AUTHORITY = 'cpan:TOBYINK';
our $VERSION   = '1.012001';

$VERSION =~ tr/_//d;

#### B doesn't provide perlstring() in 5.6. Monkey patch it.

use B ();

unless ( exists &B::perlstring ) {
	my $d;
	*B::perlstring = sub {
		no warnings 'uninitialized';
		require Data::Dumper;
		$d ||= 'Data::Dumper'
			->new( [] )->Indent( 0 )->Purity( 0 )->Pad( '' )->Useqq( 1 )
			->Terse( 1 )->Freezer( '' )->Toaster( '' );
		my $perlstring = $d->Values( [ '' . shift ] )->Dump;
		( $perlstring =~ /^"/ ) ? $perlstring : qq["$perlstring"];
	};
} #/ unless ( exists &B::perlstring)

unless ( exists &B::cstring ) {
	*B::cstring = \&B::perlstring;
}

push @B::EXPORT_OK, qw( perlstring cstring );

#### Done!

5.6;

__END__

=pod

=encoding utf-8

=for stopwords pragmas

=head1 NAME

Devel::TypeTiny::Perl56Compat - shims to allow Type::Tiny to run on Perl 5.6.x

=head1 STATUS

This module is considered part of Type-Tiny's internals. It is not
covered by the
L<Type-Tiny stability policy|Type::Tiny::Manual::Policies/"STABILITY">.

=head1 DESCRIPTION

This is not considered part of Type::Tiny's public API.

Currently this module just has one job: it patches L<B> to export a
C<perlstring> function, as this was only added in Perl 5.8.0.

=head1 BUGS

Please report any bugs to
L<https://github.com/tobyink/p5-type-tiny/issues>.

=head1 AUTHOR

Toby Inkster E<lt>tobyink@cpan.orgE<gt>.

=head1 COPYRIGHT AND LICENCE

This software is copyright (c) 2013-2014, 2017-2021 by Toby Inkster.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=head1 DISCLAIMER OF WARRANTIES

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.