summaryrefslogtreecommitdiff
path: root/lib/Locale/Maketext/GutsLoader.pm
blob: 5cce12e37b5d6ad2e834b24fecaa14a86d015008 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

package Locale::Maketext::GutsLoader;
use strict;
sub zorp { return scalar @_ }

BEGIN {
  $Locale::Maketext::GutsLoader::GUTSPATH = __FILE__;
  *Locale::Maketext::DEBUG = sub () {0}
   unless defined &Locale::Maketext::DEBUG;
}

#
# This whole drama is so that we can load the utf8'd code
# in Locale::Maketext::Guts, but if that fails, snip the
# utf8 and then try THAT.
#

$Locale::Maketext::GUTSPATH = '';
Locale::Maketext::DEBUG and print "Requiring Locale::Maketext::Guts...\n";
eval 'require Locale::Maketext::Guts';

if($@) {
  my $path = $Locale::Maketext::GUTSPATH;

  die "Can't load Locale::Maketext::Guts\nAborting" unless $path;
  
  die "No readable file $Locale::Maketext::GutsLoader::GUTSPATH\nAborting"
   unless -e $path and -f _ and -r _;

  open(IN, $path) or die "Can't read-open $path\nAborting";
  
  my $source;
  { local $/;  $source = <IN>; }
  close(IN);
  unless( $source =~ s/\b(use utf8)/# $1/ ) {
    Locale::Maketext::DEBUG and
     print "I didn't see 'use utf8' in $path\n";
  }
  eval $source;
  die "Can't compile $path\n...The error I got was:\n$@\nAborting" if $@;
  Locale::Maketext::DEBUG and print "Non-utf8'd Locale::Maketext::Guts fine\n";
} else {
  Locale::Maketext::DEBUG and print "Loaded Locale::Maketext::Guts fine\n";
}

1;