5 use File::Slurp 'slurp';
6 use List::MoreUtils 'uniq';
9 unlink 'lib/Mouse/Tiny.pm'
10 if -e 'lib/Mouse/Tiny.pm';
28 for my $file (uniq 'lib/Mouse/Util.pm', sort @files) {
29 my $contents = slurp $file;
31 $contents =~ s/__END__\b.*//s; # remove documentation
32 $contents =~ s/1;\n*$//; # remove success indicator
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;
37 $mouse_tiny .= $contents;
40 open my $handle, '>lib/Mouse/Tiny.pm' or die "Can't write lib/Mouse/Tiny.pm: $!";
42 print { $handle } << 'EOF';
43 # THIS FILE IS AUTOGENERATED!
45 # if regular Mouse is loaded, bail out
46 unless ($INC{'Mouse.pm'}) {
49 # tell Perl we already have all of the Mouse files loaded:
52 for my $file (@files) {
53 (my $inc = $file) =~ s{^lib/}{};
54 print { $handle } "\$INC{'$inc'} = __FILE__;\n";
57 print { $handle } "\n# and now their contents\n\n";
59 print { $handle } $mouse_tiny;
61 print { $handle } "END_OF_TINY\n} #unless\n\n";
63 print { $handle } << 'EOF';
69 print { $handle } "1;\n\n";