| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #! perl --			-*- coding: utf-8 -*- | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 6 |  |  | 6 |  | 19731 | use utf8; | 
|  | 6 |  |  |  |  | 54 |  | 
|  | 6 |  |  |  |  | 29 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | # EB.pm -- EekBoek Base module. | 
| 6 |  |  |  |  |  |  | # Author          : Johan Vromans | 
| 7 |  |  |  |  |  |  | # Created On      : Fri Sep 16 18:38:45 2005 | 
| 8 |  |  |  |  |  |  | # Last Modified By: Johan Vromans | 
| 9 |  |  |  |  |  |  | # Last Modified On: Tue Jan 31 12:03:31 2017 | 
| 10 |  |  |  |  |  |  | # Update Count    : 322 | 
| 11 |  |  |  |  |  |  | # Status          : Unknown, Use with caution! | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | package main; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | our $app; | 
| 16 |  |  |  |  |  |  | our $cfg; | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | package EB; | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 6 |  |  | 6 |  | 304 | use strict; | 
|  | 6 |  |  |  |  | 18 |  | 
|  | 6 |  |  |  |  | 148 |  | 
| 21 | 6 |  |  | 6 |  | 28 | use base qw(Exporter); | 
|  | 6 |  |  |  |  | 17 |  | 
|  | 6 |  |  |  |  | 509 |  | 
| 22 |  |  |  |  |  |  |  | 
| 23 | 6 |  |  | 6 |  | 1837 | use EekBoek; | 
|  | 6 |  |  |  |  | 14 |  | 
|  | 6 |  |  |  |  | 2102 |  | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | our @EXPORT; | 
| 26 |  |  |  |  |  |  | our @EXPORT_OK; | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | # Establish location of our run-time resources. | 
| 29 |  |  |  |  |  |  | my $lib; | 
| 30 |  |  |  |  |  |  | sub libfile { | 
| 31 | 0 |  |  | 0 | 0 | 0 | my ($f) = @_; | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 0 | 0 |  |  |  | 0 | unless ( $lib ) { | 
| 34 |  |  |  |  |  |  | # Cava. | 
| 35 | 0 | 0 |  |  |  | 0 | if ( $Cava::Packager::PACKAGED ) { | 
| 36 | 0 |  |  |  |  | 0 | return Cava::Packager::GetResourcePath()."/$f"; | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  | else { | 
| 39 | 0 |  |  |  |  | 0 | $lib = $INC{"EB.pm"}; | 
| 40 | 0 |  |  |  |  | 0 | $lib =~ s/EB\.pm$//; | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  | } | 
| 43 | 0 |  |  |  |  | 0 | $lib."EB/res/$f"; | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | sub findlib { | 
| 47 | 22 |  |  | 22 | 0 | 82794 | my ($file, $section) = @_; | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | # The two-argument form supports locale-dependent paths, but | 
| 50 |  |  |  |  |  |  | # we hard-wire this to 'nl'. | 
| 51 | 22 | 100 |  |  |  | 60 | if ( $section ) { | 
| 52 | 6 |  |  |  |  | 14 | my $lang = 'nl'; | 
| 53 | 6 |  |  |  |  | 27 | my $found = findlib( "$section/$lang/$file" ); | 
| 54 | 6 | 50 |  |  |  | 28 | return $found if $found; | 
| 55 | 0 |  |  |  |  | 0 | $found = findlib( "$section/$file" ); | 
| 56 | 0 | 0 |  |  |  | 0 | return $found if $found; | 
| 57 | 0 |  |  |  |  | 0 | return undef; | 
| 58 |  |  |  |  |  |  | } | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | # Cava. | 
| 61 | 16 | 50 |  |  |  | 42 | if ( $Cava::Packager::PACKAGED ) { | 
| 62 | 0 |  |  |  |  | 0 | my $found = Cava::Packager::GetUserFile($file); | 
| 63 | 0 | 0 |  |  |  | 0 | return $found if -e $found; | 
| 64 | 0 |  |  |  |  | 0 | $found = Cava::Packager::GetResource($file); | 
| 65 | 0 | 0 |  |  |  | 0 | return $found if -e $found; | 
| 66 |  |  |  |  |  |  | } | 
| 67 |  |  |  |  |  |  |  | 
| 68 | 16 |  |  |  |  | 59 | foreach ( @INC ) { | 
| 69 | 42 | 100 |  |  |  | 509 | return "$_/EB/user/$file" if -e "$_/EB/user/$file"; | 
| 70 | 39 | 100 |  |  |  | 350 | return "$_/EB/res/$file" if -e "$_/EB/res/$file"; | 
| 71 | 38 | 100 |  |  |  | 399 | return "$_/EB/$file" if -e "$_/EB/$file"; | 
| 72 |  |  |  |  |  |  | } | 
| 73 | 0 |  |  |  |  | 0 | undef; | 
| 74 |  |  |  |  |  |  | } | 
| 75 |  |  |  |  |  |  |  | 
| 76 | 6 |  |  | 6 |  | 2615 | use lib ( grep { defined } findlib("CPAN") ); | 
|  | 6 |  |  |  |  | 3193 |  | 
|  | 6 |  |  |  |  | 19 |  | 
|  | 6 |  |  |  |  | 42 |  | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | # Some standard modules (locale-free). | 
| 79 | 6 |  |  | 6 |  | 2404 | use EB::Globals; | 
|  | 6 |  |  |  |  | 16 |  | 
|  | 6 |  |  |  |  | 754 |  | 
| 80 | 6 |  |  | 6 |  | 41 | use Carp; | 
|  | 6 |  |  |  |  | 10 |  | 
|  | 6 |  |  |  |  | 347 |  | 
| 81 | 6 |  |  | 6 |  | 2029 | use Data::Dumper; | 
|  | 6 |  |  |  |  | 29709 |  | 
|  | 6 |  |  |  |  | 928 |  | 
| 82 | 6 |  |  | 6 |  | 2402 | use Carp::Assert; | 
|  | 6 |  |  |  |  | 16 |  | 
|  | 6 |  |  |  |  | 32 |  | 
| 83 | 6 |  |  | 6 |  | 1902 | use EB::Utils; | 
|  | 6 |  |  |  |  | 15 |  | 
|  | 6 |  |  |  |  | 2527 |  | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | # Even though we do not use translations, most of the code is in place. | 
| 86 | 61 |  |  | 61 |  | 242 | sub _T { $_[0] } | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | # Export our and the imported globals. | 
| 89 |  |  |  |  |  |  | @EXPORT = ( @EB::Globals::EXPORT, | 
| 90 |  |  |  |  |  |  | @EB::Utils::EXPORT, | 
| 91 |  |  |  |  |  |  | "_T",			# @EB::Locale::EXPORT, | 
| 92 |  |  |  |  |  |  | qw(carp croak),		# Carp | 
| 93 |  |  |  |  |  |  | qw(Dumper),			# Data::Dumper | 
| 94 |  |  |  |  |  |  | qw(findlib libfile),	# | 
| 95 |  |  |  |  |  |  | qw(assert affirm),		# Carp::Assert | 
| 96 |  |  |  |  |  |  | ); | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | our $ident; | 
| 99 |  |  |  |  |  |  | our $imsg; | 
| 100 |  |  |  |  |  |  | my $imsg_saved; | 
| 101 |  |  |  |  |  |  | our $url = "http://www.eekboek.nl"; | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | sub __init__ { | 
| 104 | 6 |  | 50 | 6 |  | 30 | $imsg_saved = $imsg || ""; | 
| 105 |  |  |  |  |  |  |  | 
| 106 | 6 |  |  |  |  | 12 | my $year = 2005; | 
| 107 | 6 |  |  |  |  | 288 | my $thisyear = (localtime(time))[5] + 1900; | 
| 108 | 6 | 50 |  |  |  | 40 | $year .= "-$thisyear" unless $year == $thisyear; | 
| 109 | 6 |  |  |  |  | 30 | $ident = __x("{name} {version}", | 
| 110 |  |  |  |  |  |  | name    => $EekBoek::PACKAGE, | 
| 111 |  |  |  |  |  |  | version => $EekBoek::VERSION); | 
| 112 | 6 | 50 |  |  |  | 41 | $imsg = __x("{ident}{extra} -- Copyright {year} Squirrel Consultancy", | 
| 113 |  |  |  |  |  |  | ident   => $ident, | 
| 114 |  |  |  |  |  |  | extra   => ($app ? " Wx" : ""), | 
| 115 |  |  |  |  |  |  | year    => $year); | 
| 116 | 6 | 50 | 33 |  |  | 57 | if ( $imsg ne $imsg_saved | 
|  |  |  | 33 |  |  |  |  | 
| 117 |  |  |  |  |  |  | && !( @ARGV && $ARGV[0] =~ /-(P|-?printconfig)$/ ) | 
| 118 |  |  |  |  |  |  | ) { | 
| 119 | 6 |  |  |  |  | 387 | warn($imsg, "\n"); | 
| 120 |  |  |  |  |  |  | } | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | eval { | 
| 123 | 0 |  |  |  |  | 0 | require Win32; | 
| 124 | 0 |  |  |  |  | 0 | my @a = Win32::GetOSVersion(); | 
| 125 | 0 |  |  |  |  | 0 | my ($id, $major) = @a[4,1]; | 
| 126 | 0 | 0 |  |  |  | 0 | die unless defined $id; | 
| 127 | 0 |  |  |  |  | 0 | warn(_T("EekBoek is VRIJE software, ontwikkeld om vrij over uw eigen gegevens te kunnen beschikken.")."\n"); | 
| 128 | 0 |  |  |  |  | 0 | warn(_T("Met uw keuze voor het Microsoft Windows besturingssysteem geeft u echter alle vrijheden weer uit handen. Dat is erg triest.")."\n"); | 
| 129 | 6 | 50 | 33 |  |  | 61 | } unless $imsg_saved eq $imsg || $ENV{AUTOMATED_TESTING}; | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | } | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | sub app_init { | 
| 134 | 6 |  |  | 6 | 0 | 233600 | shift;			# 'EB' | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | # Load a config file. | 
| 137 | 6 |  |  |  |  | 1408 | require EB::Config; | 
| 138 | 6 |  |  |  |  | 20 | undef $::cfg; | 
| 139 | 6 |  |  |  |  | 49 | EB::Config->init_config( @_ ); | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | # Main initialisation. | 
| 142 | 6 |  |  |  |  | 23 | __init__(); | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | # Initialise locale-dependent formats. | 
| 145 | 6 |  |  |  |  | 1612 | require EB::Format; | 
| 146 | 6 |  |  |  |  | 40 | EB::Format->init_formats(); | 
| 147 |  |  |  |  |  |  |  | 
| 148 | 6 |  |  |  |  | 18 | return $::cfg;		# until we've got something better | 
| 149 |  |  |  |  |  |  | } | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | sub EB::Config::Handler::connect_db { | 
| 152 |  |  |  |  |  |  | # Connect to the data base. | 
| 153 | 0 |  |  | 0 |  |  | require EB::DB; | 
| 154 | 0 |  |  |  |  |  | EB::DB::->connect; | 
| 155 |  |  |  |  |  |  | } | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | 1; | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | __END__ |