UNIVERSAL::new - Load a module when you call the new method on it
use UNIVERSAL::new; my $object = HTTP::Tiny->new; # HTTP::Tiny gets loaded
This module installs a universal, fallback
new method. When called, it loads the invoking module like
require would. If the module has a
new method, control is transferred to that method.
This is most useful for command line scripts via the U alias:
$ perl -MU -we 'HTTP::Tiny->new->mirror(...)'
Otherwise, you wind up repeating your module name, and that's painful for a "one-liner":
$ perl -MHTTP::Tiny -we 'HTTP::Tiny->new->mirror(...)'
If the module is not installed or if it does not have a
new method, the usual exceptions are thrown.
Warning: Mucking with UNIVERSAL is a potentially fragile, global hack that could have unintended consequences. You should not use it in production unless you are willing to accept that risk.
Please report any bugs or feature requests through the issue tracker at https://github.com/dagolden/universal-new/issues. You will be notified automatically of any progress on your issue.
This is open source software. The code repository is available for public review and contribution under the terms of the license.
David Golden <email@example.com>
This software is Copyright (c) 2013 by David Golden.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004