390 likes | 576 Views
Perl Versioning. YAPC Israel 2004. Outline. Why do I care about versions? Perl versions Module versions How-To use module versions ‘only’. Why do I care about versions. Track changes Functional Performance Fixes. Why do I care about versions. Impose dependencies
E N D
Perl Versioning YAPC Israel 2004
Outline • Why do I care about versions? • Perl versions • Module versions • How-To use module versions • ‘only’ YAPC::Israel 2004
Why do I care about versions • Track changes • Functional • Performance • Fixes YAPC::Israel 2004
Why do I care about versions • Impose dependencies • I never tested this with versions older than X • Version X.Y is broken, don’t use it • This requires support that was only added in version Z YAPC::Israel 2004
Why do I care about versions • Reporting/Fixing bugs • In what version did you see this bug? • Has it already been fixed? • Did a new release introduce the problem, or was it always there? YAPC::Israel 2004
Perl –v or $] or $^V • Perl –v • This is perl, v5.8.2 built for cygwin-multi-64int • $] = 5.008002 • number • $PERL_VERSION == $^V • literal – avoid this YAPC::Israel 2004
Perl –v or $] or $^V • Convention: • Major.Minor.Patchlevel • Minor Even/Odd = Release/Development • Examples: • 5.8.2 – latest release version • 5.9.1 – latest development version YAPC::Israel 2004
Module versions • % perl –MCPAN –e shell cpan> m CPAN DESCRIPTION Implements default import method for modules CPAN_USERID P5P (The Perl5 Porters Mailing List <perl5-porters@perl.org>) CPAN_VERSION 1.76 INST_FILE /usr/lib/perl5/5.8.0/CPAN.pm INST_VERSION 1.75 YAPC::Israel 2004
Module Versions • $CPAN::VERSION = 1.76 • In general: • $module::VERSION YAPC::Israel 2004
Module Versions • Convention: • Major.Minor • Use a floating point number • Maintain the same number of decimal points • 5.008 < 5.08 < 5.8 YAPC::Israel 2004
How-To USE module versions • Use use • use version; • use module; • use module version; • version and module are bare-words YAPC::Israel 2004
USE’ing versions • use version; • use 5.8.0; • Use Perl version at least 5.8.0 • Newer versions are ok YAPC::Israel 2004
USE’ing modules • use module; • use cpan; • Include the cpan module • Don’t check the version YAPC::Israel 2004
USE’ing module versions • use module version; • Use Net::Telnet 3.0; • Include Net::Telnet only if the version is at least 3.0 • Otherwise, die YAPC::Israel 2004
Specifying the version (old way) package Some::Module; use vars qw($VERSION); $VERSION = "4.03"; YAPC::Israel 2004
Specifying the version (correct) package Some::Module; BEGIN { our $VERSION; $VERSION = "4.03"; } YAPC::Israel 2004
Specifying the version (best) package Some::Module; require Exporter; @ISA = qw(Exporter); BEGIN { our $VERSION; $VERSION = "4.03"; } YAPC::Israel 2004
Why did we use BEGIN? • Use is an implicit BEGIN • We want to know what version we are working with even if we have not yet processed the file YAPC::Israel 2004
How does it work • Exporter checks the version when attempting to import a number $module->require_version($version) • Exporter supplies a default method YAPC::Israel 2004
Is this good enough? • Track Changes • Impose Dependencies • Reporting/Fixing bugs • What else? YAPC::Israel 2004
I need exactly this version! • 2.3 does not have the right support • 2.4 works • 2.5 is broken • 2.6 is good • How do we require only version 2.4? • There is no obvious way to do this YAPC::Israel 2004
only • New package by Brian Ingerson • Now we can say: use only myModule => 1.4 YAPC::Israel 2004
Only options • Require exactly the versions that we know to be working • Supports ranges ‘1.3-1.5’ • Supports exceptions ‘!1.35’ • Supports exactly ‘2.45’ YAPC::Israel 2004
Only example • use only myModule => ‘1.1 1.3-1.5 !1.35 1.6-’; • Exactly v1.1 • Anything in the range v1.3 to v1.5 • But not 1.35 • Anything at least as new as 1.6 YAPC::Israel 2004
only - Basic usage • Install the only package • Don’t change any packages Package Foo; our $VERSION; $VERSION = 1.5; Package Bar; use only Foo => 1.5; YAPC::Israel 2004
Multiple versions • My cron jobs use version 1.6 • I am developing version 1.7 • If I install 1.7 for testing, all those depending on the package may fail! • Solution 1: Install 1.7 in a different place and play with @INC. YAPC::Israel 2004
only can manage installation directories automatically Installation now supports more than one concurrent version cd myModule-1.3 perl Makefile.PL make test make –Monly=install only – multiple versions YAPC::Israel 2004
only – multiple versions • myModule-1.6 is currently installed • Scripts use ‘use myModule’; • I want to test myModule-1.7 YAPC::Israel 2004
only – multiple versions • Option 1: • Other packages use ‘use myModule’ • Install new version using ‘make –Monly’ • It will not only be accessible via ‘use only’ • Test with ‘only only myModule;’ YAPC::Israel 2004
only – multiple versions • Option 2: • Other packages use ‘use only myModule;’ • Install new version using ‘make –Monly’ as version 0.1. • Test with ‘use only myModule => 0.1;’ YAPC::Israel 2004
Modperl • Running multiple systems in the same interpreter • What if they require different versions? • Perl cannot currently install multiple versions of a given module YAPC::Israel 2004
Modperl -- only • only can specify what you want on a per package basis • only cannot currently import the same package with different versions YAPC::Israel 2004
Other systems • Compiled languages do not support version dependencies • Most scripted languages do not support versioning • Why should Perl? • Is this overkill? YAPC::Israel 2004
Compiled languages • Compiled languages (C, C++) use • version control systems • search paths YAPC::Israel 2004
Run time languages • Languages that include libraries on the fly • Java • Perl • Unix YAPC::Israel 2004
Run time languages • Name libraries uniquely • libc.so.3.64 • Pray that no-one changed the environment YAPC::Israel 2004
Size counts • Large production systems are static • Versions are managed externally • Shoot anyone who touches the system YAPC::Israel 2004
Size counts • Small systems are more easily managed • Most scripted systems are small • The problem occurs when scripts collide • Multiple systems on the same platform YAPC::Israel 2004
Review • $] • $VERSION • use • only YAPC::Israel 2004