Skip to content

Commit a5c6b04

Browse files
committed
Replace all uses of B::perlstring with XString
B has a lot of code and uses a lot of memory to load. XString just provide B::perlstring without anything else.
1 parent 19e8641 commit a5c6b04

File tree

17 files changed

+59
-24
lines changed

17 files changed

+59
-24
lines changed

Changes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{{$NEXT}}
22

3+
- Replaced the use of B with XString if it is installed. The latter is much
4+
smaller and provides the one subroutine from B we cared about. Based on GH
5+
#15. Implemented by Nicolas R.
6+
7+
38
0.43 2018-10-26
49

510
- Optimized compile-time operations to make Specio itself quicker to

cpanfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ requires "Sub::Quote" => "0";
1515
requires "Test::Fatal" => "0";
1616
requires "Test::More" => "0.96";
1717
requires "Try::Tiny" => "0";
18-
requires "XString" => "0";
1918
requires "overload" => "0";
2019
requires "parent" => "0";
2120
requires "perl" => "5.008";
@@ -25,6 +24,7 @@ requires "version" => "0.83";
2524
requires "warnings" => "0";
2625
recommends "Ref::Util" => "0.112";
2726
recommends "Sub::Util" => "1.40";
27+
recommends "XString" => "0";
2828

2929
on 'test' => sub {
3030
requires "ExtUtils::MakeMaker" => "0";

dist.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Test::TidyAll.minimum_perl = 5.010000
2121
[Prereqs::Soften]
2222
module = Ref::Util
2323
module = Sub::Util
24+
module = XString
2425

2526
[Prereqs / DevelopRequires]
2627
Moo = 0

lib/Specio.pm

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,30 @@ coercions and parameterizable types. This is a misfeature.
386386
387387
=back
388388
389+
=head1 OPTIONAL PREREQS
390+
391+
There are several optional prereqs that if installed will make this
392+
distribution better in some way.
393+
394+
=over 4
395+
396+
=item * L<Ref::Util>
397+
398+
Installing this will speed up a number of type checks for built-in types.
399+
400+
=item * L<XString>
401+
402+
If this is installed it will be loaded instead of the L<B> module if you have
403+
Perl 5.10 or greater. This module is much more memory efficient than loading
404+
all of L<B>.
405+
406+
=item * L<Sub::Util> or L<Sub::Name>
407+
408+
If one of these is installed then stack traces that end up in Specio code will
409+
have much better subroutine names for any frames.
410+
411+
=back
412+
389413
=head1 WHY THE NAME?
390414
391415
This distro was originally called "Type", but that's an awfully generic top

lib/Specio/Constraint/AnyCan.pm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use warnings;
55

66
our $VERSION = '0.44';
77

8-
use B ();
98
use List::Util 1.33 ();
109
use Role::Tiny::With;
1110
use Scalar::Util ();
11+
use Specio::Helpers qw( perlstring );
1212
use Specio::Library::Builtins;
1313
use Specio::OO;
1414

@@ -25,8 +25,7 @@ with 'Specio::Constraint::Role::CanType';
2525
my $self = shift;
2626
my $val = shift;
2727

28-
my $methods = join ', ',
29-
map { B::perlstring($_) } @{ $self->methods };
28+
my $methods = join ', ', map { perlstring($_) } @{ $self->methods };
3029
return sprintf( <<'EOF', $val, $methods );
3130
(
3231
do {

lib/Specio/Constraint/AnyDoes.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use warnings;
55

66
our $VERSION = '0.44';
77

8-
use B ();
98
use Role::Tiny::With;
109
use Scalar::Util ();
10+
use Specio::Helpers qw( perlstring );
1111
use Specio::Library::Builtins;
1212
use Specio::OO;
1313

@@ -24,7 +24,7 @@ with 'Specio::Constraint::Role::DoesType';
2424
my $self = shift;
2525
my $val = shift;
2626

27-
return sprintf( <<'EOF', ($val) x 8, B::perlstring( $self->role ) );
27+
return sprintf( <<'EOF', ($val) x 8, perlstring( $self->role ) );
2828
(
2929
(
3030
Scalar::Util::blessed(%s) || (

lib/Specio/Constraint/AnyIsa.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use warnings;
55

66
our $VERSION = '0.44';
77

8-
use B ();
98
use Role::Tiny::With;
109
use Scalar::Util ();
10+
use Specio::Helpers qw( perlstring );
1111
use Specio::Library::Builtins;
1212
use Specio::OO;
1313

@@ -24,7 +24,7 @@ with 'Specio::Constraint::Role::IsaType';
2424
my $self = shift;
2525
my $val = shift;
2626

27-
return sprintf( <<'EOF', ($val) x 7, B::perlstring( $self->class ) );
27+
return sprintf( <<'EOF', ($val) x 7, perlstring( $self->class ) );
2828
(
2929
(
3030
Scalar::Util::blessed(%s)

lib/Specio/Constraint/Enum.pm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use warnings;
55

66
our $VERSION = '0.44';
77

8-
use B ();
98
use Role::Tiny::With;
109
use Scalar::Util qw( refaddr );
1110
use Specio::Library::Builtins;

lib/Specio/Constraint/ObjectCan.pm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use warnings;
55

66
our $VERSION = '0.44';
77

8-
use B ();
98
use List::Util 1.33 ();
109
use Role::Tiny::With;
1110
use Scalar::Util ();
11+
use Specio::Helpers qw( perlstring );
1212
use Specio::Library::Builtins;
1313
use Specio::OO;
1414

@@ -25,8 +25,7 @@ with 'Specio::Constraint::Role::CanType';
2525
my $self = shift;
2626
my $val = shift;
2727

28-
my $methods = join ', ',
29-
map { B::perlstring($_) } @{ $self->methods };
28+
my $methods = join ', ', map { perlstring($_) } @{ $self->methods };
3029
return sprintf( <<'EOF', $val, $methods );
3130
(
3231
do {

lib/Specio/Constraint/ObjectDoes.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use warnings;
55

66
our $VERSION = '0.44';
77

8-
use B ();
98
use Role::Tiny::With;
109
use Scalar::Util ();
10+
use Specio::Helpers qw( perlstring );
1111
use Specio::Library::Builtins;
1212
use Specio::OO;
1313

@@ -24,7 +24,7 @@ with 'Specio::Constraint::Role::DoesType';
2424
my $self = shift;
2525
my $val = shift;
2626

27-
return sprintf( <<'EOF', ($val) x 3, B::perlstring( $self->role ) );
27+
return sprintf( <<'EOF', ($val) x 3, perlstring( $self->role ) );
2828
( Scalar::Util::blessed(%s) && %s->can('does') && %s->does(%s) )
2929
EOF
3030
};

0 commit comments

Comments
 (0)