Add note to general methods
[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
0d2fef85 9require 'lib/Mouse/Spec.pm';
10
11my $MouseTinyFile = shift || 'lib/Mouse/Tiny.pm';
f1db776d 12
13my @files;
14
15find({
cae2769d 16 wanted => sub {
17 push @files, $_
18 if -f $_
0d2fef85 19 && /\.pm$/
26cf84ad 20 && !/Squirrel/
0d2fef85 21 && !/Tiny/
22 && !/Spec/ # has no functionality
23 && !/TypeRegistry/ # deprecated
24 && !/\bouse/ # ouse.pm
cae2769d 25 },
f1db776d 26 no_chdir => 1,
27}, 'lib');
28
29my $mouse_tiny = '';
30
0d2fef85 31for my $file (uniq
32 'lib/Mouse/Exporter.pm',
33 'lib/Mouse/Util.pm',
34 'lib/Mouse/Meta/TypeConstraint.pm',
35 'lib/Mouse/Util/TypeConstraints.pm',
36 sort @files) {
37
f1db776d 38 my $contents = slurp $file;
39
40 $contents =~ s/__END__\b.*//s; # remove documentation
41 $contents =~ s/1;\n*$//; # remove success indicator
f1db776d 42
0d2fef85 43 $mouse_tiny .= "BEGIN{ # #file\n";
f1db776d 44 $mouse_tiny .= $contents;
0d2fef85 45 $mouse_tiny .= "}\n";
f1db776d 46}
47
0d2fef85 48open my $handle, ">$MouseTinyFile";
f1db776d 49
0d2fef85 50print { $handle } << "EOF";
51# This file was generated by $0 from Mouse $Mouse::Spec::VERSION.
52#
53# ANY CHANGES MADE HERE WILL BE LOST!
f1db776d 54
0d2fef85 55EOF
56
57print { $handle } << 'EOF';
f1db776d 58# if regular Mouse is loaded, bail out
2da0530e 59unless ($INC{'Mouse.pm'}) {
f1db776d 60EOF
61
62for my $file (@files) {
63 (my $inc = $file) =~ s{^lib/}{};
0d2fef85 64 printf { $handle } "%-45s = __FILE__;\n", "\$INC{'$inc'}";
f1db776d 65}
66
0d2fef85 67print { $handle } << 'EOF';
68eval sprintf("#line %d %s\n", __LINE__, __FILE__) . <<'END_OF_TINY';
69
70# tell Perl we already have all of the Mouse files loaded:
71EOF
72
f1db776d 73print { $handle } "\n# and now their contents\n\n";
74
75print { $handle } $mouse_tiny;
2da0530e 76
0d2fef85 77print { $handle } << 'EOF';
78END_OF_TINY
79 die $@ if $@;
80} # unless Mouse.pm is loaded
81EOF
2da0530e 82
83print { $handle } << 'EOF';
84package Mouse::Tiny;
2da0530e 85
bc69ee88 86Mouse::Exporter->setup_import_methods(also => 'Mouse');
87
0d2fef85 881;
2da0530e 89EOF
90
0d2fef85 91close $handle;