in reply to Re^2: Use and Require - making an informed choice.
in thread Use and Require - making an informed choice.

A minor comment on the call to DDS:

sub rarelyusedfunction { my $self = shift; my $cl = Foo::CodeLoader->new(); $cl->load('DDS'); my $dds = Data::Dump::Streamer->new; $dds->Dump($self)->Out(); }

I would write that as follows:

sub rarelyusedfunction { my $self = shift; if ( eval { require Data::Dump::Streamer; 1 } ) { return scalar Data::Dump::Streamer::Dump($self)->Out(); } else { warn "**DANGER** Falling back to Data::Dumper as DDS" . " isn't available"; require Data::Dumper; return Data::Dumper::Dumper($self) } }

The scalar there is useful, as Out() behaves differently in list and scalar context (something that was probably a mistake in hindsight and which might change in the next release, I've been putting serious consideration into changing the interface somewhat in version 2).

I've never bothered with any Autouse stuff personally. The pattern

if ( eval { require Foo; 1 } ) { .. } else { ... }

is simple enough I think.

---
$world=~s/war/peace/g