Method modifiers are implemented in Mouse
[gitmo/Mouse.git] / author / generate-mouse-tiny.pl
CommitLineData
f1db776d 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use File::Find;
5use File::Slurp 'slurp';
6use List::MoreUtils 'uniq';
49540190 7use autodie;
f1db776d 8
e0541d44 9unlink 'lib/Mouse/Tiny.pm'
10 if -e 'lib/Mouse/Tiny.pm';
f1db776d 11
12my @files;
13
14find({
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
25my $mouse_tiny = '';
26
27for 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 39open my $handle, '>lib/Mouse/Tiny.pm' or die "Can't write lib/Mouse/Tiny.pm: $!";
40
41print { $handle } << 'EOF';
f1db776d 42# THIS FILE IS AUTOGENERATED!
43
44# if regular Mouse is loaded, bail out
2da0530e 45unless ($INC{'Mouse.pm'}) {
448fbe32 46eval <<'END_OF_TINY';
f1db776d 47
48# tell Perl we already have all of the Mouse files loaded:
49EOF
50
51for my $file (@files) {
52 (my $inc = $file) =~ s{^lib/}{};
53 print { $handle } "\$INC{'$inc'} = __FILE__;\n";
54}
55
56print { $handle } "\n# and now their contents\n\n";
57
58print { $handle } $mouse_tiny;
2da0530e 59
448fbe32 60print { $handle } "END_OF_TINY\n} #unless\n\n";
2da0530e 61
62print { $handle } << 'EOF';
63package Mouse::Tiny;
64use base 'Mouse';
65
66EOF
67
f1db776d 68print { $handle } "1;\n\n";
69