[Pdx-pm] Austin's $VERSION trick

Michael G Schwern schwern at pobox.com
Fri Jul 15 14:50:11 PDT 2005


On Fri, Jul 15, 2005 at 02:22:43PM -0700, David Wheeler wrote:
> Will this force Perl to re-load Hello::World::Version from disk for  
> every module that requires it?

Yes.

> If so, why not add a method to it?

Because...

>   package Hello::World::Version;
>   sub ver { return '0.01' }
> 
> Then:
> 
>   our $Hello::World::VERSION = require Hello::World::Version &&  
> Hello::World::Version::ver;

...I think the length of that statement says it all.  Remember what we're
trying to replace:

	# lib/Hello/World/Version.pm
	package Hello::World;

	our $VERSION = 1.00;

	# lib/Hello/World.pm
	package Hello::World;

	our $VERSION = require Hello::World::Version && $Hello::World::VERSION;

Which is, ironically, shorter.  Now repeat that for 50 .pm files.

Also, I'm willing to bet that reloading a 3 line Perl module really has
no significant performance effect especially given that this technique is
really of use in large systems.  And I'll bet a method call is even slower.


> And either way, this won't fix those implementations (such as  
> search.cpan.org) that don't evaluate *any* perl code when searching  
> for the version number...

Yeah, Andreas noted that when he saw SVK doing this.  They're working
something out by putting version numbers into the provides slot of META.yml
and having the CPAN indexers use that.  META.yml finally has a use.


-- 
Michael G Schwern     schwern at pobox.com     http://www.pobox.com/~schwern
You are wicked and wrong to have broken inside and peeked at the
implementation and then relied upon it.
	-- tchrist in <31832.969261130 at chthon>


More information about the Pdx-pm-list mailing list