http://www.perlmonks.org?node_id=1041332


in reply to CPAN Trojan Horses

The easy way to do optional dependencies is along these lines:

use constant HAS_LWP => eval "require LWP::UserAgent"; ...; update_cache() if HAS_LWP; my $data = read_cache();

In terms of META.yml/META.json, there is a facility to indicate optional dependencies, though I don't see it used very often.

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name