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