XPRESS/hub.pm untested

filter: Statementstmt 0.0% 0 / 113 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 174 CC 9 SCAR 19.3
CC
9
Cov
0%
Instrument
20.0
DataFile
6.0
Sweep
6.0
CRAP 6.9
1 package Lab::XPRESS::hub;
2 $Lab::XPRESS::hub::VERSION = '3.899';
3 #ABSTRACT: The XPRESS main hub
4  
5 use v5.20;
6  
7 use Lab::Exception;
8 use strict;
9 use Exporter 'import';
10 use Module::Load qw/load autoload/;
11 use Try::Tiny;
12 use Carp;
13  
14 our @EXPORT_OK = qw(DataFile Sweep Frame Instrument Connection);
15  
16 sub new {
17 my $proto = shift;
18 my $class = ref($proto) || $proto;
19  
20 my $self = {};
21 bless( $self, $class );
22  
23 return $self;
24  
25 }
26  
27 sub DataFile {
28 my $self = shift if ref( $_[0] ) eq __PACKAGE__;
29 my ( $filenamebase, $foldername ) = @_;
30  
31 use Lab::XPRESS::Data::XPRESS_DataFile;
32 my $xFile
33 = new Lab::XPRESS::Data::XPRESS_DataFile( $filenamebase, $foldername )
34 or die Lab::Exception::CorruptParameter->throw(
35 error => "Can't open file $filenamebase\n" );
36 return $xFile;
37  
38 }
39  
40 sub Sweep {
41 my $self = shift if ref( $_[0] ) eq __PACKAGE__;
42 my $sweep = shift;
43  
44 $sweep = "Lab::XPRESS::Sweep::" . $sweep;
45 eval "require $sweep; $sweep->import(); 1;"
46 or do Lab::Exception::CorruptParameter->throw( error => $@ );
47  
48 return $sweep->new(@_);
49  
50 }
51  
52 sub Frame {
53 my $self = shift if ref( $_[0] ) eq __PACKAGE__;
54  
55 my $frame = "Lab::XPRESS::Sweep::Frame";
56 eval "require $frame; $frame->import(); 1;"
57 or do Lab::Exception::CorruptParameter->throw( error => $@ );
58  
59 #or do Lab::Exception::CorruptParameter->throw( error => "Can't locate module $frame\n" );
60  
61 return $frame->new(@_);
62  
63 }
64  
65 sub Instrument {
66 my $self = shift;
67 my $instrument;
68 if ( ref($self) eq __PACKAGE__ ) {
69 $instrument = shift;
70 }
71 else {
72 $instrument = $self;
73 }
74  
75 my $module = "Lab::Instrument::" . $instrument;
76 my $found_module;
77  
78 try {
79 autoload($module);
80 $found_module = 1;
81 }
82 catch {
83 # Do not try to load a Moose driver, if the problem is just
84 # a syntax error in the non-Moose driver.
85 if ( $_ =~ /Compilation failed in require/ ) {
86 die $_;
87 }
88 };
89  
90 if ($found_module) {
91 return $module->new(@_);
92 }
93  
94 $module = "Lab::Moose::Instrument::" . $instrument;
95 load($module);
96  
97 my $args_ref = shift;
98 my $connection_type = delete $args_ref->{connection_type};
99  
100 # Somewhat problematic, as the args_ref mixes connection options
101 # with instrument options. => Better use the Lab::Moose constructor ;)
102 return $module->new(
103 connection_type => $connection_type,
104 connection_options => $args_ref,
105 %{$args_ref},
106 );
107 }
108  
109 sub Connection {
110 my $self = shift if ref( $_[0] ) eq __PACKAGE__;
111 my $connection = shift;
112  
113 $connection = "Lab::Connection::" . $connection;
114 eval "require $connection; $connection->import(); 1;"
115 or do Lab::Exception::CorruptParameter->throw( error => $@ );
116  
117 #or do Lab::Exception::CorruptParameter->throw( error => "Can't locate module $connection\n" );
118  
119 return $connection->new(@_);
120  
121 }
122  
123 sub show_available_objects {
124 my $self = shift if ref( $_[0] ) eq __PACKAGE__;
125  
126 my $xDIR = $INC{"Lab/XPRESS/hub.pm"};
127 $xDIR =~ s/hub.pm//g;
128  
129 opendir( DIR, $xDIR . "Sweep" );
130 my @sweeps = readdir(DIR);
131 shift @sweeps; # shift "."
132 shift @sweeps; # shift ".."
133  
134 $xDIR =~ s/XPRESS\///g;
135 opendir( DIR, $xDIR . "Instrument" );
136 my @instruments = readdir(DIR);
137 shift @instruments; # shift "."
138 shift @instruments; # shift ".."
139  
140 $xDIR =~ s/Instrument\///g;
141 opendir( DIR, $xDIR . "Connection" );
142 my @connections = readdir(DIR);
143 shift @connections; # shift "."
144 shift @connections; # shift ".."
145  
146 print "\n\n";
147 print "================\n";
148 print " XPRESS add-on: \n";
149 print "================\n";
150 print "\n\n";
151  
152 print "available connections:\n";
153 print "--------------------------\n";
154 foreach my $module (@connections) {
155 $module =~ s/\.pm//g;
156 print $module. "\n";
157 }
158 print "--------------------------\n";
159 print "\n\n";
160  
161 print "available Instruments:\n";
162 print "--------------------------\n";
163 foreach my $module (@instruments) {
164 $module =~ s/\.pm//g;
165 print $module. "\n";
166 }
167 print "--------------------------\n";
168 print "\n\n";
169  
170 print "available sweep modules:\n";
171 print "--------------------------\n";
172 foreach my $module (@sweeps) {
173 $module =~ s/\.pm//g;
174 print $module. "\n";
175 }
176 print "--------------------------\n";
177 print "\n\n";
178  
179 }
180  
181 1;
182  
183 __END__