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