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