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   10 use strict;
  2         2  
  2         60  
4 2     2   6 use warnings;
  2         7  
  2         68  
5              
6 2     2   6 use Carp;
  2         3  
  2         88  
7 2     2   7 use Config;
  2         2  
  2         63  
8              
9 2     2   741 use My::Module::Recommend::Any qw{ __any };
  2         4  
  2         156  
10 2     2   632 use My::Module::Recommend::All qw{ __all };
  2         4  
  2         1196  
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             my %core = map { $_ => 1 } qw{ Time::HiRes };
150              
151             sub optional_modules {
152 1     1 1 3 my ( undef, %arg ) = @_;
153             defined $arg{core}
154 1 50       4 or $arg{core} = 1;
155 1         1 my %rslt;
156 1         2 foreach my $opt ( @optionals ) {
157 13         16 foreach my $m ( $opt->__modules() ) {
158 16 50 66     22 if ( ! $core{$m->[0]} || $arg{core} ) {
159 16   100     43 $rslt{$m->[0]} = $m->[1] || 0;
160             }
161             }
162             }
163 1         3 return \%rslt;
164             }
165              
166             sub optional_modules_to_hide {
167 0     0 1   my ( $invocant, %arg ) = @_;
168             defined $arg{core}
169 0 0         or $arg{core} = 0;
170 0           return ( sort keys %{ $invocant->optional_modules( %arg ) } );
  0            
171             }
172              
173             sub recommend {
174 0     0 1   my $need_some;
175 0           foreach my $mod ( @optionals ) {
176 0 0         defined( my $msg = $mod->recommend() )
177             or next;
178 0 0         $need_some++
179             or warn <<'EOD';
180              
181             The following optional modules were not available:
182             EOD
183 0           warn "\n$msg";
184             }
185             $need_some
186 0 0         and warn <<'EOD';
187              
188             It is not necessary to install these now. If you decide to install them
189             later, this software will make use of them when it finds them.
190              
191             EOD
192              
193 0           return;
194             }
195              
196             1;
197              
198             __END__