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