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 | |
e3ca3ad0 |
10 | print "Generate Mouse::Tiny ...\n"; |
11 | |
dc8e9f34 |
12 | sub slurp { |
13 | open my $in, '<', $_[0]; |
14 | local $/; |
15 | return scalar <$in>; |
16 | } |
17 | sub uniq{ |
18 | my %seen; |
19 | return grep{ !$seen{$_}++ } @_; |
20 | } |
f1db776d |
21 | |
0d2fef85 |
22 | require 'lib/Mouse/Spec.pm'; |
23 | |
24 | my $MouseTinyFile = shift || 'lib/Mouse/Tiny.pm'; |
f1db776d |
25 | |
26 | my @files; |
27 | |
28 | find({ |
cae2769d |
29 | wanted => sub { |
30 | push @files, $_ |
31 | if -f $_ |
0d2fef85 |
32 | && /\.pm$/ |
26cf84ad |
33 | && !/Squirrel/ |
0d2fef85 |
34 | && !/Tiny/ |
35 | && !/Spec/ # has no functionality |
36 | && !/TypeRegistry/ # deprecated |
37 | && !/\bouse/ # ouse.pm |
cae2769d |
38 | }, |
f1db776d |
39 | no_chdir => 1, |
40 | }, 'lib'); |
41 | |
42 | my $mouse_tiny = ''; |
43 | |
0d2fef85 |
44 | for my $file (uniq |
43e49d93 |
45 | 'lib/Mouse/PurePerl.pm', |
0d2fef85 |
46 | 'lib/Mouse/Exporter.pm', |
47 | 'lib/Mouse/Util.pm', |
48 | 'lib/Mouse/Meta/TypeConstraint.pm', |
49 | 'lib/Mouse/Util/TypeConstraints.pm', |
50 | sort @files) { |
51 | |
f1db776d |
52 | my $contents = slurp $file; |
53 | |
54 | $contents =~ s/__END__\b.*//s; # remove documentation |
55 | $contents =~ s/1;\n*$//; # remove success indicator |
f1db776d |
56 | |
7801fbf0 |
57 | $mouse_tiny .= "BEGIN{ # $file\n"; |
f1db776d |
58 | $mouse_tiny .= $contents; |
0d2fef85 |
59 | $mouse_tiny .= "}\n"; |
f1db776d |
60 | } |
61 | |
0d2fef85 |
62 | open my $handle, ">$MouseTinyFile"; |
f1db776d |
63 | |
0d2fef85 |
64 | print { $handle } << "EOF"; |
65 | # This file was generated by $0 from Mouse $Mouse::Spec::VERSION. |
66 | # |
67 | # ANY CHANGES MADE HERE WILL BE LOST! |
f1db776d |
68 | |
0d2fef85 |
69 | EOF |
70 | |
71 | print { $handle } << 'EOF'; |
f1db776d |
72 | # if regular Mouse is loaded, bail out |
2da0530e |
73 | unless ($INC{'Mouse.pm'}) { |
6e64f809 |
74 | # tell Perl we already have all of the Mouse files loaded: |
f1db776d |
75 | EOF |
76 | |
77 | for my $file (@files) { |
78 | (my $inc = $file) =~ s{^lib/}{}; |
0d2fef85 |
79 | printf { $handle } "%-45s = __FILE__;\n", "\$INC{'$inc'}"; |
f1db776d |
80 | } |
81 | |
0d2fef85 |
82 | print { $handle } << 'EOF'; |
83 | eval sprintf("#line %d %s\n", __LINE__, __FILE__) . <<'END_OF_TINY'; |
0d2fef85 |
84 | EOF |
85 | |
f1db776d |
86 | print { $handle } "\n# and now their contents\n\n"; |
87 | |
88 | print { $handle } $mouse_tiny; |
2da0530e |
89 | |
0d2fef85 |
90 | print { $handle } << 'EOF'; |
91 | END_OF_TINY |
92 | die $@ if $@; |
93 | } # unless Mouse.pm is loaded |
94 | EOF |
2da0530e |
95 | |
96 | print { $handle } << 'EOF'; |
97 | package Mouse::Tiny; |
2da0530e |
98 | |
bc69ee88 |
99 | Mouse::Exporter->setup_import_methods(also => 'Mouse'); |
100 | |
0d2fef85 |
101 | 1; |
3654f7fa |
102 | __END__ |
103 | |
104 | =head1 NAME |
105 | |
106 | Mouse::Tiny - Mouse in a single file |
107 | |
108 | =head1 DESCRIPTION |
109 | |
110 | Mouse::Tiny is just Mouse itself, but it is in a single file. |
111 | |
112 | This is B<not> tiny. In fact, it requires a little more memory and time than Mouse. |
113 | |
114 | Use Mouse directly unless you know what you do. |
115 | |
116 | =cut |
117 | |
2da0530e |
118 | EOF |
119 | |
0d2fef85 |
120 | close $handle; |
e3ca3ad0 |
121 | |
122 | print "done.\n"; |