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