blib/lib/QWizard/Generator/Best.pm untested

filter: Statementstmt 0.0% 0 / 54 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 99 CC 12 SCAR 45.5
CC
12
Cov
0%
new
156.0
BEGIN
2.0
BEGIN
2.0
CRAP 94.4
1 package QWizard::Generator::Best;
2  
3 use strict;
4 use Config;
5 our $VERSION = '3.15';
6  
7 sub new {
8 my $type = shift;
9  
10 # first check if we're in a web server...
11 # XXX: there is probably a better way to determine things than this.
12 if (exists($ENV{'SERVER_NAME'})) {
13 my $have_html = eval { require QWizard::Generator::HTML };
14 if (!$have_html) {
15 die "We're in a web server and we can't load the QWizard::Generator::HTML module\n";
16 }
17 return new QWizard::Generator::HTML(@_);
18 }
19  
20 # see if they have a preference and if we can use it
21 if (exists($ENV{'QWIZARD_GENERATOR'})) {
22 my $class = $ENV{'QWIZARD_GENERATOR'};
23 if ($class !~ /::/) {
24 $class = "QWizard::Generator::" . $class;
25 }
26 my $haveit =
27 eval "require $class;";
28 if ($haveit) {
29 return eval "new " . $class . "();"
30 } else {
31 print STDERR "requested QWizard Generator $class could not be loaded\n";
32 }
33 }
34  
35 # checks to see if we're running on win32, macos or have the X11 DISLAY var
36 my $havedisplay = ($^O eq 'MSWin32' ||
37 $Config{'ccflags'} =~ /-D_?WIN32_?/ ||
38 $^O eq 'MacOS' ||
39 defined($ENV{'DISPLAY'}));
40  
41 # console like
42 my $have_gtk2 =
43 eval {
44 if (!$havedisplay) {
45 return 0;
46 }
47 require QWizard::Generator::Gtk2;
48 };
49 # ideally, Gtk2 is the current nicest interface. Try it.
50 return new QWizard::Generator::Gtk2(@_) if ($have_gtk2);
51  
52 # console like
53 my $have_tk =
54 eval {
55 if (!$havedisplay) {
56 return 0;
57 }
58 require QWizard::Generator::Tk;
59 };
60 # ideally, Tk is the second nicest interface. Try it.
61 return new QWizard::Generator::Tk(@_) if ($have_tk);
62  
63 my $have_curses = eval { require QWizard::Generator::Curses };
64 # next try the curses interface, if available
65 return new QWizard::Generator::Curses(@_) if ($have_curses);
66  
67 my $have_readline = eval { require QWizard::Generator::ReadLine };
68 # next try the curses interface, if available
69 return new QWizard::Generator::ReadLine(@_) if ($have_readline);
70  
71 # remote client: future
72 my $have_wap = eval { require QWizard::Generator::WAP };
73  
74 die "Sorry, I couldn't find a suitable QWizard::Generator perl module to use. XXX: describe solution alternatives to the user (eg, how to install a module).\n";
75 }
76  
77 1;