File Coverage

blib/lib/EB.pm
Criterion Covered Total %
statement 77 96 80.2
branch 24 48 50.0
condition 8 20 40.0
subroutine 14 15 93.3
pod 0 3 0.0
total 123 182 67.5


line stmt bran cond sub pod time code
1             #! perl -- -*- coding: utf-8 -*-
2              
3 6     6   17577 use utf8;
  6         34  
  6         22  
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: Wed Mar 23 11:17:11 2011
10             # Update Count : 320
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   271 use strict;
  6         7  
  6         118  
21 6     6   17 use base qw(Exporter);
  6         7  
  6         535  
22              
23 6     6   1625 use EekBoek;
  6         9  
  6         2691  
24              
25             our @EXPORT;
26             our @EXPORT_OK;
27              
28             # Establish location of our run-time resources.
29             my $lib;
30             sub libfile {
31 6     6 0 10 my ($f) = @_;
32              
33 6 50       14 unless ( $lib ) {
34             # Cava.
35 6 50       14 if ( $Cava::Packager::PACKAGED ) {
36 0         0 return Cava::Packager::GetResourcePath()."/$f";
37             }
38             else {
39 6         12 $lib = $INC{"EB.pm"};
40 6         29 $lib =~ s/EB\.pm$//;
41             }
42             }
43 6         23 $lib."EB/res/$f";
44             }
45              
46             sub findlib {
47 28     28 0 85872 my ($file, $section) = @_;
48              
49             # The two-argument form supports locale-dependent paths.
50 28 100 66     107 if ( $section && $cfg ) {
    50          
51 6         19 my $lang = $cfg->val( qw( locale lang ), "" );
52 6 50       16 if ( $lang =~ /\./ ) {
53 0         0 my $found = findlib( "$section/$lang/$file" );
54 0 0       0 return $found if $found;
55 0         0 $lang =~ s/\..*//; # strip .utf8
56             }
57 6 50       16 if ( $lang =~ /_/ ) {
58 6         21 my $found = findlib( "$section/$lang/$file" );
59 6 50       16 return $found if $found;
60 6         27 $lang =~ s/_.*//; # strip _US
61             }
62 6 50       17 if ( $lang ) {
63 6         18 my $found = findlib( "$section/$lang/$file" );
64 6 50       22 return $found if $found;
65             }
66 0         0 return undef;
67             }
68             elsif ( $section ) {
69 0         0 $file = "$section/$file";
70             }
71              
72             # Cava.
73 22 50       36 if ( $Cava::Packager::PACKAGED ) {
74 0         0 my $found = Cava::Packager::GetUserFile($file);
75 0 0       0 return $found if -e $found;
76 0         0 $found = Cava::Packager::GetResource($file);
77 0 0       0 return $found if -e $found;
78             }
79              
80 22         33 foreach ( @INC ) {
81 126 100       1350 return "$_/EB/user/$file" if -e "$_/EB/user/$file";
82 123 100       960 return "$_/EB/res/$file" if -e "$_/EB/res/$file";
83 122 100       954 return "$_/EB/$file" if -e "$_/EB/$file";
84             }
85 6         14 undef;
86             }
87              
88 6     6   2871 use lib ( grep { defined } findlib("CPAN") );
  6         2651  
  6         15  
  6         37  
89              
90             # Some standard modules (locale-free).
91 6     6   2282 use EB::Globals;
  6         10  
  6         718  
92 6     6   24 use Carp;
  6         7  
  6         295  
93 6     6   2199 use Data::Dumper;
  6         26084  
  6         320  
94 6     6   2020 use Carp::Assert;
  6         10  
  6         26  
95 6     6   1862 use EB::Utils;
  6         9  
  6         2761  
96              
97             # Export our and the imported globals.
98             @EXPORT = ( @EB::Globals::EXPORT,
99             @EB::Utils::EXPORT,
100             "_T", # @EB::Locale::EXPORT,
101             qw(carp croak), # Carp
102             qw(Dumper), # Data::Dumper
103             qw(findlib libfile), #
104             qw(assert affirm), # Carp::Assert
105             );
106              
107             our $ident;
108             our $imsg;
109             my $imsg_saved;
110             our $url = "http://www.eekboek.nl";
111              
112             sub __init__ {
113 6   50 6   25 $imsg_saved = $imsg || "";
114              
115             # The CLI and GUI use different EB::Locale modules.
116 6 50 33     37 if ( $app || $Cava::Packager::PACKAGED && !Cava::Packager::IsLinux() ) {
      33        
117             # We do not have a good gettext for Windows, so use Wx.
118             # It's packaged anyway.
119 0         0 require EB::Wx::Locale; # provides EB::Locale, really
120             }
121             else {
122 6         1954 require EB::Locale;
123             }
124 6         204 EB::Locale::->import;
125 6         24 EB::Locale->set_language($ENV{LANG});
126              
127 6         15 my $year = 2005;
128 6         97 my $thisyear = (localtime(time))[5] + 1900;
129 6 50       35 $year .= "-$thisyear" unless $year == $thisyear;
130 6         36 $ident = __x("{name} {version}",
131             name => $EekBoek::PACKAGE,
132             version => $EekBoek::VERSION);
133 6         8 my @locextra;
134 6 50       16 push(@locextra, _T("Nederlands")) if $EB::Locale::LOCALISER;
135 6 50       37 $imsg = __x("{ident}{extra}{locale} -- Copyright {year} Squirrel Consultancy",
    50          
136             ident => $ident,
137             extra => ($app ? " Wx" : ""),
138             locale => (@locextra ? " (".join(", ", @locextra).")" : ""),
139             year => $year);
140 6 50 33     54 if ( $imsg ne $imsg_saved
      33        
141             && !( @ARGV && $ARGV[0] =~ /-(P|-?printconfig)$/ )
142             ) {
143 6         243 warn($imsg, "\n");
144             }
145              
146             eval {
147 0         0 require Win32;
148 0         0 my @a = Win32::GetOSVersion();
149 0         0 my ($id, $major) = @a[4,1];
150 0 0       0 die unless defined $id;
151 0         0 warn(_T("EekBoek is VRIJE software, ontwikkeld om vrij over uw eigen gegevens te kunnen beschikken.")."\n");
152 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");
153 6 50 33     55 } unless $imsg_saved eq $imsg || $ENV{AUTOMATED_TESTING};
154              
155             }
156              
157             sub app_init {
158 6     6 0 223457 shift; # 'EB'
159              
160             # Load a config file.
161 6         1488 require EB::Config;
162 6         13 undef $::cfg;
163 6         30 EB::Config->init_config( @_ );
164              
165             # Main initialisation.
166 6         10 __init__();
167              
168             # Initialise locale-dependent formats.
169 6         1410 require EB::Format;
170 6         28 EB::Format->init_formats();
171              
172 6         9 return $::cfg; # until we've got something better
173             }
174              
175             sub EB::Config::Handler::connect_db {
176             # Connect to the data base.
177 0     0     require EB::DB;
178 0           EB::DB::->connect;
179             }
180              
181             1;
182              
183             __END__