File Coverage

inc/My/Module/Recommend.pm
Criterion Covered Total %
statement 26 42 61.9
branch 2 14 14.2
condition 4 5 80.0
subroutine 7 10 70.0
pod 3 3 100.0
total 42 74 56.7


line stmt bran cond sub pod time code
1             package My::Module::Recommend;
2              
3 2     2   16 use strict;
  2         6  
  2         95  
4 2     2   12 use warnings;
  2         5  
  2         138  
5              
6 2     2   14 use Carp;
  2         5  
  2         162  
7 2     2   13 use Config;
  2         4  
  2         168  
8              
9 2     2   1181 use My::Module::Recommend::Any qw{ __any };
  2         6  
  2         205  
10 2     2   1170 use My::Module::Recommend::All qw{ __all };
  2         6  
  2         2150  
11              
12             my ( $is_5_010, $is_5_012 );
13              
14             if ( $] ge '5.012' ) {
15             $is_5_012 = $is_5_010 = 1;
16             } elsif ( $] ge '5.010' ) {
17             $is_5_010 = 1;
18             };
19              
20             my %misbehaving_os = map { $_ => 1 } qw{ MSWin32 cygwin };
21              
22             my @optionals = (
23             __any( 'Astro::Coord::ECI::TLE::Iridium' => <<'EOD' ),
24             This module is needed if you wish to compute Iridium Classic flare
25             events. If you do not intend to do this, this module is not
26             needed.
27             EOD
28             __any( 'Astro::SIMBAD::Client' => <<'EOD' ),
29             This module is required for the 'lookup' subcommand of the
30             Astro::App::Satpass2 sky() method, which retrieves astronomical
31             objects from the SIMBAD database. If you do not intend to use
32             this functionality, Astro::SIMBAD::Client is not needed.
33             EOD
34             __any( 'Astro::SpaceTrack=0.105' => <<'EOD' ),
35             This module is required for the Astro::App::Satpass2 spacetrack()
36             method, which retrieves satellite TLE data from Space Track and
37             other web sites. Version 0.105 is needed because of a change in
38             the way help is displayed. If you intend to get your TLEs
39             externally to this package (say, with a web browser or curl),
40             Astro::SpaceTrack is not needed.
41             EOD
42             __any( 'Browser::Open' => <<'EOD' ),
43             This module is being phased in as the only supported way to
44             display web-based help. If you intend to leave the 'webcmd'
45             attribute false, this module is not needed.
46             EOD
47             __any( 'Date::Manip' => <<'EOD' .
48             This module is not required, but the alternative to installing it
49             is to specify times in ISO 8601 format. See 'SPECIFYING TIMES' in
50             the 'Astro::App::Satpass2' documentation for the details.
51             EOD
52             ( $is_5_010 ? '' : <<'EOD' ) ),
53              
54             Unfortunately, the current Date::Manip requires Perl 5.10. Since
55             you are running an earlier Perl, you can try installing Date-Manip
56             5.54, which is the most recent version that does _not_ require
57             Perl 5.10. This version of Date::Manip does not understand summer
58             time (a.k.a. daylight saving time).
59             EOD
60             __all( qw{ DateTime DateTime::TimeZone } => <<'EOD' ),
61             These modules are used to format times, and provide full time zone
62             support. If they are not installed, POSIX::strftime() will be
63             used, and you may find that you can not display correct local
64             times for zones other than your system's default zone or GMT. They
65             will also be used (if available) by the ISO8601 time parser
66             because they go farther into the past than Time::Local does.
67             EOD
68              
69             # CAVEAT:
70             #
71             # Unfortunately as things currently stand, the version needs to be
72             # maintained three places:
73             # - lib/Astro/App/Satpass2/Utils.pm
74             # - inc/My/Module/Recommend.pm
75             # - inc/My/Module/Test/App.pm
76             # These all need to stay the same. Sigh.
77             # Any such should be in xt/author/consistent_module_versions.t
78              
79             __any( 'DateTime::Calendar::Christian=0.06' => <<'EOD' ),
80             This module is used to parse (maybe) and format dates that might
81             be either Julian or Gregorian. Currently the only parser that has
82             this capability is ISO8601. If historical dates in the proleptic
83             Gregorian calendar are fine with you, you do not need this module.
84             EOD
85             __any( 'Geo::Coder::OSM' => <<'EOD' ),
86             This module is required for the Astro::App::Satpass2 geocode()
87             method, which computes latitude and longitude based on street
88             address. If you do not intend to determine your observing
89             locations this way, this module is not needed.
90             EOD
91             __any( 'Geo::WebService::Elevation::USGS' => <<'EOD' ),
92             This module is required for the Astro::App::Satpass2 height()
93             method, which determines height above the reference ellipsoid for
94             a given latitude and longitude. If you do not intend to determine
95             your observing locations this way, this module is not needed.
96             EOD
97             __all( qw{ LWP::UserAgent LWP::Protocol URI } => <<'EOD' ),
98             These modules are required if you want to use URLs in the init(),
99             load(), or source() methods. If you do not intend to use URLs
100             there, you do not need these packages. All three packages are
101             requirements for most of the other Internet-access functionality,
102             so you may get them implicitly if you install some of the other
103             optional modules.
104             EOD
105             __any( qw{ Term::ReadLine } => <<'EOD' ),
106             This module is required for interactive command recall and
107             editing.
108             EOD
109             __any( qw{ Term::ReadLine::Perl } => <<'EOD' ),
110             This module is required for interactive command completion.
111             EOD
112             $is_5_012 ? () : __any( 'Time::y2038' => <<'EOD' .
113             This module is not required, but if installed allows you to do
114             computations for times outside the usual range of system epoch to
115             system epoch + 0x7FFFFFFF seconds.
116             EOD
117             ( $misbehaving_os{$^O} ? <<"EOD" : '' ) .
118              
119             Unfortunately, Time::y2038 has been known to misbehave when
120             running under $^O, so you may be better off just accepting the
121             restricted time range.
122             EOD
123             ( ( $Config{use64bitint} || $Config{use64bitall} ) ? <<'EOD' : '' )
124              
125             Since your Perl appears to support 64-bit integers, you may well
126             not need Time::y2038 to do computations for times outside the
127             so-called 'usual range.' Time::y2038 will be used, though, if it
128             is available.
129             EOD
130             ),
131             __any( 'Time::HiRes' => <<'EOD' ),
132             This module is required only for the time() command/method. If
133             you do not plan to use this method you do not need this module.
134             EOD
135             );
136              
137             # Expose the module version so we can test for consistent definition.
138             sub __module_version {
139 0     0   0 my $module = $_[-1];
140 0         0 foreach my $opt ( @optionals ) {
141 0         0 foreach my $m ( $opt->__modules() ) {
142 0 0       0 $module eq $m->[0]
143             and return $m->[1];
144             }
145             }
146 0         0 confess "Bug - Module $module is not optional";
147             }
148              
149              
150             my %core = map { $_ => 1 } qw{ Time::HiRes };
151              
152             sub optional_modules {
153 1     1 1 3 my ( undef, %arg ) = @_;
154             defined $arg{core}
155 1 50       6 or $arg{core} = 1;
156 1         3 my %rslt;
157 1         3 foreach my $opt ( @optionals ) {
158 13         34 foreach my $m ( $opt->__modules() ) {
159 16 50 66     51 if ( ! $core{$m->[0]} || $arg{core} ) {
160 16   100     68 $rslt{$m->[0]} = $m->[1] || 0;
161             }
162             }
163             }
164 1         5 return \%rslt;
165             }
166              
167             sub optional_modules_to_hide {
168 0     0 1   my ( $invocant, %arg ) = @_;
169             defined $arg{core}
170 0 0         or $arg{core} = 0;
171 0           return ( sort keys %{ $invocant->optional_modules( %arg ) } );
  0            
172             }
173              
174             sub recommend {
175 0     0 1   my $need_some;
176 0           foreach my $mod ( @optionals ) {
177 0 0         defined( my $msg = $mod->recommend() )
178             or next;
179 0 0         $need_some++
180             or warn <<'EOD';
181              
182             The following optional modules were not available:
183             EOD
184 0           warn "\n$msg";
185             }
186             $need_some
187 0 0         and warn <<'EOD';
188              
189             It is not necessary to install these now. If you decide to install them
190             later, this software will make use of them when it finds them.
191              
192             EOD
193              
194 0           return;
195             }
196              
197             1;
198              
199             __END__