From: Shawn M Moore Date: Sun, 28 Sep 2008 19:04:11 +0000 (+0000) Subject: First stab at generating Mouse::Tiny X-Git-Tag: 0.19~183 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f1db776d2defca7822f4f88fa9cbca8f89890198;p=gitmo%2FMouse.git First stab at generating Mouse::Tiny --- diff --git a/generate-mouse-tiny.pl b/generate-mouse-tiny.pl new file mode 100755 index 0000000..c4c104a --- /dev/null +++ b/generate-mouse-tiny.pl @@ -0,0 +1,59 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use File::Find; +use File::Slurp 'slurp'; +use List::MoreUtils 'uniq'; + +unlink 'lib/Mouse/Tiny.pm'; + +my @files; + +find({ + wanted => sub { push @files, $_ if -f $_ && !/Squirrel/ }, + no_chdir => 1, +}, 'lib'); + +my $mouse_tiny = ''; + +for my $file (uniq 'lib/Mouse/Util.pm', sort @files) { + my $contents = slurp $file; + + $contents =~ s/__END__\b.*//s; # remove documentation + $contents =~ s/1;\n*$//; # remove success indicator + $contents =~ s/^.*\n//; # remove shebang + + $contents =~ s/^use Mouse\S*\s*\n//mg; # we're already loading everything + $contents =~ s/^use (Mouse\S*)\s*(.+);/BEGIN { $1->import($2) }/mg; + + $mouse_tiny .= $contents; +} + +$mouse_tiny .= << 'EOF'; +package Mouse::Tiny; +use base 'Mouse'; + +EOF + +open my $handle, '>lib/Mouse/Tiny.pm' or die "Can't write lib/Mouse/Tiny.pm: $!"; + +print { $handle } << 'EOF'; +#!/usr/bin/env perl +# THIS FILE IS AUTOGENERATED! + +# if regular Mouse is loaded, bail out +# XXX: TODO + +# tell Perl we already have all of the Mouse files loaded: +EOF + +for my $file (@files) { + (my $inc = $file) =~ s{^lib/}{}; + print { $handle } "\$INC{'$inc'} = __FILE__;\n"; +} + +print { $handle } "\n# and now their contents\n\n"; + +print { $handle } $mouse_tiny; +print { $handle } "1;\n\n"; +