Mouse code has a lot of '{' and '}', q{} is dangerous.
[gitmo/Mouse.git] / author / generate-mouse-tiny.pl
CommitLineData
f1db776d 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use File::Find;
5use File::Slurp 'slurp';
6use List::MoreUtils 'uniq';
7
8unlink 'lib/Mouse/Tiny.pm';
9
10my @files;
11
12find({
cae2769d 13 wanted => sub {
14 push @files, $_
15 if -f $_
26cf84ad 16 && !/Squirrel/
cae2769d 17 && !/\bouse/
26cf84ad 18 && !/\.sw[po]$/
cae2769d 19 },
f1db776d 20 no_chdir => 1,
21}, 'lib');
22
23my $mouse_tiny = '';
24
25for my $file (uniq 'lib/Mouse/Util.pm', sort @files) {
26 my $contents = slurp $file;
27
28 $contents =~ s/__END__\b.*//s; # remove documentation
29 $contents =~ s/1;\n*$//; # remove success indicator
f1db776d 30
31 $contents =~ s/^use Mouse\S*\s*\n//mg; # we're already loading everything
32 $contents =~ s/^use (Mouse\S*)\s*(.+);/BEGIN { $1->import($2) }/mg;
33
34 $mouse_tiny .= $contents;
35}
36
f1db776d 37open my $handle, '>lib/Mouse/Tiny.pm' or die "Can't write lib/Mouse/Tiny.pm: $!";
38
39print { $handle } << 'EOF';
f1db776d 40# THIS FILE IS AUTOGENERATED!
41
42# if regular Mouse is loaded, bail out
2da0530e 43unless ($INC{'Mouse.pm'}) {
448fbe32 44eval <<'END_OF_TINY';
f1db776d 45
46# tell Perl we already have all of the Mouse files loaded:
47EOF
48
49for my $file (@files) {
50 (my $inc = $file) =~ s{^lib/}{};
51 print { $handle } "\$INC{'$inc'} = __FILE__;\n";
52}
53
54print { $handle } "\n# and now their contents\n\n";
55
56print { $handle } $mouse_tiny;
2da0530e 57
448fbe32 58print { $handle } "END_OF_TINY\n} #unless\n\n";
2da0530e 59
60print { $handle } << 'EOF';
61package Mouse::Tiny;
62use base 'Mouse';
63
64EOF
65
f1db776d 66print { $handle } "1;\n\n";
67