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   12 use strict;
  2         4  
  2         140  
4 2     2   10 use warnings;
  2         5  
  2         99  
5              
6 2     2   9 use Carp;
  2         4  
  2         123  
7 2     2   10 use Config;
  2         4  
  2         106  
8              
9 2     2   943 use My::Module::Recommend::Any qw{ __any };
  2         6  
  2         166  
10 2     2   941 use My::Module::Recommend::All qw{ __all };
  2         5  
  2         1654  
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             $is_5_012 ? () : __any( 'Time::y2038' => <<'EOD' .
110             This module is not required, but if installed allows you to do
111             computations for times outside the usual range of system epoch to
112             system epoch + 0x7FFFFFFF seconds.
113             EOD
114             ( $misbehaving_os{$^O} ? <<"EOD" : '' ) .
115              
116             Unfortunately, Time::y2038 has been known to misbehave when
117             running under $^O, so you may be better off just accepting the
118             restricted time range.
119             EOD
120             ( ( $Config{use64bitint} || $Config{use64bitall} ) ? <<'EOD' : '' )
121              
122             Since your Perl appears to support 64-bit integers, you may well
123             not need Time::y2038 to do computations for times outside the
124             so-called 'usual range.' Time::y2038 will be used, though, if it
125             is available.
126             EOD
127             ),
128             __any( 'Time::HiRes' => <<'EOD' ),
129             This module is required only for the time() command/method. If
130             you do not plan to use this method you do not need this module.
131             EOD
132             );
133              
134             # Expose the module version so we can test for consistent definition.
135             sub __module_version {
136 0     0   0 my $module = $_[-1];
137 0         0 foreach my $opt ( @optionals ) {
138 0         0 foreach my $m ( $opt->__modules() ) {
139 0 0       0 $module eq $m->[0]
140             and return $m->[1];
141             }
142             }
143 0         0 confess "Bug - Module $module is not optional";
144             }
145              
146              
147             my %core = map { $_ => 1 } qw{ Time::HiRes };
148              
149             sub optional_modules {
150 1     1 1 3 my ( undef, %arg ) = @_;
151             defined $arg{core}
152 1 50       5 or $arg{core} = 1;
153 1         2 my %rslt;
154 1         2 foreach my $opt ( @optionals ) {
155 12         26 foreach my $m ( $opt->__modules() ) {
156 15 50 66     43 if ( ! $core{$m->[0]} || $arg{core} ) {
157 15   100     63 $rslt{$m->[0]} = $m->[1] || 0;
158             }
159             }
160             }
161 1         5 return \%rslt;
162             }
163              
164             sub optional_modules_to_hide {
165 0     0 1   my ( $invocant, %arg ) = @_;
166             defined $arg{core}
167 0 0         or $arg{core} = 0;
168 0           return ( sort keys %{ $invocant->optional_modules( %arg ) } );
  0            
169             }
170              
171             sub recommend {
172 0     0 1   my $need_some;
173 0           foreach my $mod ( @optionals ) {
174 0 0         defined( my $msg = $mod->recommend() )
175             or next;
176 0 0         $need_some++
177             or warn <<'EOD';
178              
179             The following optional modules were not available:
180             EOD
181 0           warn "\n$msg";
182             }
183             $need_some
184 0 0         and warn <<'EOD';
185              
186             It is not necessary to install these now. If you decide to install them
187             later, this software will make use of them when it finds them.
188              
189             EOD
190              
191 0           return;
192             }
193              
194             1;
195              
196             __END__