]> Raphaël G. Git Repositories - binary/blob - cpack
Support file name with spaces
[binary] / cpack
1 #! /usr/bin/perl
2
3 # Best practice
4 use strict;
5 use warnings;
6
7 # Load POSIX
8 use POSIX qw(EXIT_SUCCESS EXIT_FAILURE);
9
10 # Load CSS::Packer
11 use CSS::Packer;
12
13 # Init compress
14 my $compress = 'pretty';
15
16 # Filter options
17 @ARGV = map { if ($_ eq '-p' || $_ eq '--pretty') { $compress = 'pretty'; (); } elsif ($_ eq '-m' || $_ eq '--minify') { $compress = 'minify'; (); } else { $_; } } @ARGV;
18
19 # Show usage with invalid argument or stdin opened to a tty
20 if (scalar(@ARGV) || -t STDIN) {
21 print "Usage: $0 [-p|--pretty|-m|--minify] < input.css > output.css\n";
22 exit EXIT_FAILURE;
23 }
24
25 # Instantiate packer object
26 my $packer = CSS::Packer->init();
27
28 # Load input in variable
29 my $input = do { local $/; <STDIN> };
30
31 # Minify input with required compression
32 $packer->minify(\$input, compress => $compress);
33
34 # Show result
35 print $input;
36
37 # Exit with success
38 exit EXIT_SUCCESS;
39
40 __END__
41
42 =head1 NAME
43
44 Cpack - A simple perl CSS minifier
45
46 =head1 VERSION
47
48 Version 0.1
49
50 =head1 DESCRIPTION
51
52 A fast pure Perl CSS minifier script.
53
54 =head1 AUTHOR
55
56 Raphaël Gertz (Rapsys) << <git at rapsys.eu> >>.
57
58 =head1 COPYRIGHT & LICENSE
59
60 Copyright 2016 - 2017 Raphaël Gertz, all rights reserved.
61
62 This program is free software: you can redistribute it and/or modify
63 it under the terms of the GNU General Public License as published by
64 the Free Software Foundation, either version 3 of the License, or
65 (at your option) any later version.
66
67 This program is distributed in the hope that it will be useful,
68 but WITHOUT ANY WARRANTY; without even the implied warranty of
69 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70 GNU General Public License for more details.
71
72 You should have received a copy of the GNU General Public License
73 along with this program. If not, see <http://www.gnu.org/licenses/>.
74
75 =head1 SEE ALSO
76
77 L<CSS::Packer>
78
79 =cut