5 use File::Slurp 'slurp';
6 use List::MoreUtils 'uniq';
9 unlink 'lib/Mouse/Tiny.pm'
10 if -e 'lib/Mouse/Tiny.pm';
27 for my $file (uniq 'lib/Mouse/Util.pm', sort @files) {
28 my $contents = slurp $file;
30 $contents =~ s/__END__\b.*//s; # remove documentation
31 $contents =~ s/1;\n*$//; # remove success indicator
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;
36 $mouse_tiny .= $contents;
39 open my $handle, '>lib/Mouse/Tiny.pm' or die "Can't write lib/Mouse/Tiny.pm: $!";
41 print { $handle } << 'EOF';
42 # THIS FILE IS AUTOGENERATED!
44 # if regular Mouse is loaded, bail out
45 unless ($INC{'Mouse.pm'}) {
48 # tell Perl we already have all of the Mouse files loaded:
51 for my $file (@files) {
52 (my $inc = $file) =~ s{^lib/}{};
53 print { $handle } "\$INC{'$inc'} = __FILE__;\n";
56 print { $handle } "\n# and now their contents\n\n";
58 print { $handle } $mouse_tiny;
60 print { $handle } "END_OF_TINY\n} #unless\n\n";
62 print { $handle } << 'EOF';
68 print { $handle } "1;\n\n";