6fdd34a9e1285660beb18918a987c732da94072a
[p5sagit/Excel-Template.git] / Makefile.PL
1 use ExtUtils::MakeMaker;
2 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
3 # the contents of the Makefile that is written.
4
5 use File::Spec;
6
7 my $prereqs = {
8     'Test::Simple'            => 0.44,
9     'XML::Parser'             => 0.01,
10     'IO::File'                => 0.01,
11     'File::Basename'          => 0.01,
12     'Spreadsheet::WriteExcel' => 0.42,
13 };
14
15 # The assumption is the 5.8.0 and greater doesn't need Unicode::String.
16 if ($] < 5.008)
17 {
18     print "Do you want Unicode support? ";
19     my $answer = <STDIN>;
20     my $need_unicode = $answer =~ /^[Yy]/;
21
22     my $use_unicode = 0;
23     if ($need_unicode)
24     {
25             $prereqs{'Unicode::String'} = '0.01';
26             $use_unicode = 1;
27     }
28 }
29
30 use_unicode($use_unicode);
31
32 WriteMakefile(
33     NAME         => 'Excel::Template',
34     VERSION_FROM => 'lib/Excel/Template.pm', # finds $VERSION
35     AUTHOR       => 'Rob Kinyon (rob.kinyon@gmail.com)',
36     ABSTRACT     => 'Excel::Template',
37     PREREQ_PM    => $prereqs,
38 );
39
40 sub use_unicode
41 {
42     my $using_unicode = shift;
43
44     my @filenames = map {
45         File::Spec->catfile(
46             qw( lib Excel Template ),
47             @{$_},
48         )
49     } ( [ qw( Element Cell.pm_ ) ], [ qw( TextObject.pm_ ) ] );
50
51     foreach my $filename (@filenames)
52     {
53         open(IN_FILE, $filename)
54             or die "Cannot open '$filename' for reading: $!\n";
55         my @lines = <IN_FILE>;
56         close(IN_FILE);
57
58         if ($using_unicode)
59         {
60             for (@lines)
61             {
62                 s/^UNI_YES / /;
63                 s/^UNI_NO  /#/;
64             }
65         }
66         else
67         {
68             for (@lines)
69             {
70                 s/^UNI_YES /#/;
71                 s/^UNI_NO  / /;
72             }
73         }
74
75         $filename =~ s/_$//;
76         open(OUT_FILE, ">$filename")
77             or die "Cannot open '$filename' for writing: $!\n";
78         print OUT_FILE @lines;
79         close(OUT_FILE);
80     }
81
82     return 1;
83 }