Part of the reason I created MooX::Press and portable::loader was to create classes that were divorced from the Perl namespace, so you can have different versions of the same API which don't stomp on each others' namespaces.

Try this for an example:

git clone git@github.com:tobyink/misc-versioned-library-example-p5.git cd misc-versioned-library-example-p5 curl -fsSL --compressed https://git.io/cpm | perl - install perl -Ilocal example.pl

(Assumes you have Perl 5.10+, git, and curl.)

This is the contents of example.pl:

#!/usr/bin/env perl use strict; use warnings; use feature 'say'; use portable::lib './lib'; use portable::alias 'Foo-1.0' => 'FooOld'; use portable::alias 'Foo-1.1' => 'Foo'; # Foo 1.0 my $bar = FooOld->new_bar( name => 'X', desc => 'Y' ); say $bar->desc; # Foo 1.1 changed 'desc' to 'description' $bar = Foo->new_bar( name => 'X', description => 'Y' ); say $bar->description;

And here's the definition of Foo 1.1:

use strict; use warnings; return { version => '1.1', class => { 'Bar' => { has => { 'name' => { type => 'Str' }, 'description' => { type => 'Str' }, }, }, }, }

You could add a method to the Bar class like this:

'Bar' => { has => { 'name' => { type => 'Str' }, 'description' => { type => 'Str' }, }, can => { 'do_something' => sub { my $self = shift; return 42 }, }, },

In reply to Re: help with versioning modules by tobyink
in thread help with versioning modules by Special_K

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.