Commit | Line | Data |
f1db776d |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings; |
4 | use File::Find; |
5 | use File::Slurp 'slurp'; |
6 | use List::MoreUtils 'uniq'; |
49540190 |
7 | use autodie; |
f1db776d |
8 | |
0d2fef85 |
9 | require 'lib/Mouse/Spec.pm'; |
10 | |
11 | my $MouseTinyFile = shift || 'lib/Mouse/Tiny.pm'; |
f1db776d |
12 | |
13 | my @files; |
14 | |
15 | find({ |
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 | |
29 | my $mouse_tiny = ''; |
30 | |
0d2fef85 |
31 | for 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 |
48 | open my $handle, ">$MouseTinyFile"; |
f1db776d |
49 | |
0d2fef85 |
50 | print { $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 |
55 | EOF |
56 | |
57 | print { $handle } << 'EOF'; |
f1db776d |
58 | # if regular Mouse is loaded, bail out |
2da0530e |
59 | unless ($INC{'Mouse.pm'}) { |
f1db776d |
60 | EOF |
61 | |
62 | for my $file (@files) { |
63 | (my $inc = $file) =~ s{^lib/}{}; |
0d2fef85 |
64 | printf { $handle } "%-45s = __FILE__;\n", "\$INC{'$inc'}"; |
f1db776d |
65 | } |
66 | |
0d2fef85 |
67 | print { $handle } << 'EOF'; |
68 | eval sprintf("#line %d %s\n", __LINE__, __FILE__) . <<'END_OF_TINY'; |
69 | |
70 | # tell Perl we already have all of the Mouse files loaded: |
71 | EOF |
72 | |
f1db776d |
73 | print { $handle } "\n# and now their contents\n\n"; |
74 | |
75 | print { $handle } $mouse_tiny; |
2da0530e |
76 | |
0d2fef85 |
77 | print { $handle } << 'EOF'; |
78 | END_OF_TINY |
79 | die $@ if $@; |
80 | } # unless Mouse.pm is loaded |
81 | EOF |
2da0530e |
82 | |
83 | print { $handle } << 'EOF'; |
84 | package Mouse::Tiny; |
2da0530e |
85 | |
bc69ee88 |
86 | Mouse::Exporter->setup_import_methods(also => 'Mouse'); |
87 | |
0d2fef85 |
88 | 1; |
2da0530e |
89 | EOF |
90 | |
0d2fef85 |
91 | close $handle; |