houseabsolute / Exception-Class

A module that allows you to declare real exception classes in Perl
https://metacpan.org/release/Exception-Class/
Other
2 stars 5 forks source link

Version number on created classes is always hardcoded at 1.1 #16

Open petdance opened 1 year ago

petdance commented 1 year ago
#!/usr/bin/perl

use warnings;
use strict;
use 5.012;

package Itchy 51.50;

use Exception::Class (
    'Itchy' => {
        isa         => 'Exception::Class',
        description => 'blah blah',
    },
);

package Scratchy 21.12;

package Wobbly;

use Exception::Class (
    'Wobbly' => {
        isa         => 'Exception::Class',
        description => 'blah blah',
    },
);

our $VERSION = 90.125;

package main;

say 'Itchy is ', $Itchy::VERSION;
say 'Scratchy is ', $Scratchy::VERSION;
say 'Wobbly is ', $Wobbly::VERSION;
$ perl foo.pl
Itchy is 1.1
Scratchy is 21.12
Wobbly is 90.125

Even though the Itchy package has the version number declared as 51.50, the _make_subclass method always sets $VERSION to 1.1.

So if I want to have a class that is generated by Exception::Class I have to set the VERSION separately.

autarch commented 1 year ago

I think it'd be possible to just use the $VERSION from the package that uses Exception::Class. The issue there might be that the use happens at compile time and it might be before our $VERSION is set.