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