From: gfx Date: Thu, 8 Oct 2009 04:27:32 +0000 (+0900) Subject: Fix author/generate-mouse-tiny.pl. Now Mouse::Tiny is generated in the "make" command X-Git-Tag: 0.37_04~20 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0d2fef85388af5e7762027f149cf6a3c6bd36649;p=gitmo%2FMouse.git Fix author/generate-mouse-tiny.pl. Now Mouse::Tiny is generated in the "make" command --- diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP index 9ba4f9d..0b9f67c 100644 --- a/MANIFEST.SKIP +++ b/MANIFEST.SKIP @@ -45,3 +45,5 @@ nytprof author/benchmarks author/externals + +lib/Mouse/Tiny\.pm$ diff --git a/Makefile.PL b/Makefile.PL index df76048..39b0fe7 100755 --- a/Makefile.PL +++ b/Makefile.PL @@ -19,6 +19,8 @@ include 'Test::Exception'; # work around 0.27_0x (its use of diehook might be wr recommends 'MRO::Compat' if $] < 5.010; +makemaker_args PL_FILES => { 'author/generate-mouse-tiny.pl' => 'lib/Mouse/Tiny.pm' }; + if ($Module::Install::AUTHOR) { local @INC = ('lib', @INC); require 'lib/Mouse/Spec.pm'; @@ -34,7 +36,6 @@ if ($Module::Install::AUTHOR) { } else { print "you don't have Moose $require_version. skipping moose compatibility test\n"; } - system("author/generate-mouse-tiny.pl"); } WriteAll check_nmake => 0; diff --git a/author/generate-mouse-tiny.pl b/author/generate-mouse-tiny.pl index 4799507..9e4120d 100755 --- a/author/generate-mouse-tiny.pl +++ b/author/generate-mouse-tiny.pl @@ -6,8 +6,9 @@ use File::Slurp 'slurp'; use List::MoreUtils 'uniq'; use autodie; -unlink 'lib/Mouse/Tiny.pm' - if -e 'lib/Mouse/Tiny.pm'; +require 'lib/Mouse/Spec.pm'; + +my $MouseTinyFile = shift || 'lib/Mouse/Tiny.pm'; my @files; @@ -15,58 +16,76 @@ find({ wanted => sub { push @files, $_ if -f $_ + && /\.pm$/ && !/Squirrel/ - && !/TypeRegistory/ - && !/\bouse/ - && !/\.sw[po]$/ + && !/Tiny/ + && !/Spec/ # has no functionality + && !/TypeRegistry/ # deprecated + && !/\bouse/ # ouse.pm }, no_chdir => 1, }, 'lib'); my $mouse_tiny = ''; -for my $file (uniq 'lib/Mouse/Util.pm', sort @files) { +for my $file (uniq + 'lib/Mouse/Exporter.pm', + 'lib/Mouse/Util.pm', + 'lib/Mouse/Meta/TypeConstraint.pm', + 'lib/Mouse/Util/TypeConstraints.pm', + sort @files) { + my $contents = slurp $file; $contents =~ s/__END__\b.*//s; # remove documentation $contents =~ s/1;\n*$//; # remove success indicator - $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 .= "BEGIN{ # #file\n"; $mouse_tiny .= $contents; + $mouse_tiny .= "}\n"; } -open my $handle, '>lib/Mouse/Tiny.pm' or die "Can't write lib/Mouse/Tiny.pm: $!"; +open my $handle, ">$MouseTinyFile"; -print { $handle } << 'EOF'; -# THIS FILE IS AUTOGENERATED! +print { $handle } << "EOF"; +# This file was generated by $0 from Mouse $Mouse::Spec::VERSION. +# +# ANY CHANGES MADE HERE WILL BE LOST! +EOF + +print { $handle } << 'EOF'; # if regular Mouse is loaded, bail out unless ($INC{'Mouse.pm'}) { -eval <<'END_OF_TINY'; - -# 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"; + printf { $handle } "%-45s = __FILE__;\n", "\$INC{'$inc'}"; } +print { $handle } << 'EOF'; +eval sprintf("#line %d %s\n", __LINE__, __FILE__) . <<'END_OF_TINY'; + +# tell Perl we already have all of the Mouse files loaded: +EOF + print { $handle } "\n# and now their contents\n\n"; print { $handle } $mouse_tiny; -print { $handle } "END_OF_TINY\n} #unless\n\n"; +print { $handle } << 'EOF'; +END_OF_TINY + die $@ if $@; +} # unless Mouse.pm is loaded +EOF print { $handle } << 'EOF'; package Mouse::Tiny; -use base 'Mouse'; Mouse::Exporter->setup_import_methods(also => 'Mouse'); +1; EOF -print { $handle } "1;\n\n"; - +close $handle;