Skip to content

Commit

Permalink
Add to_decimal and to_dotted_decimal methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Leont committed Apr 27, 2024
1 parent e011c73 commit bd54c16
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/version.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ our (@ISA, $STRICT, $LAX);
*version::new = \&version::vpp::new;
*version::numify = \&version::vpp::numify;
*version::normal = \&version::vpp::normal;
*version::to_decimal = \&version::vpp::to_decimal;
*version::to_dotted_decimal = \&version::vpp::to_dotted_decimal;
if ($] >= 5.009000) {
no strict 'refs';
*version::stringify = \&version::vpp::stringify;
Expand All @@ -47,6 +49,8 @@ our (@ISA, $STRICT, $LAX);
*version::new = \&version::vxs::new;
*version::numify = \&version::vxs::numify;
*version::normal = \&version::vxs::normal;
*version::to_decimal = \&version::vxs::to_decimal;
*version::to_dotted_decimal = \&version::vxs::to_dotted_decimal;
if ($] >= 5.009000) {
no strict 'refs';
*version::stringify = \&version::vxs::stringify;
Expand Down
10 changes: 10 additions & 0 deletions vperl/vpp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,16 @@ sub stringify {
: $self->numify;
}

sub to_decimal {
my ($self) = @_;
return ref($self)->new($self->numify);
}

sub to_dotted_decimal {
my ($self) = @_;
return ref($self)->new($self->normal);
}

sub vcmp {
my ($left,$right,$swap) = @_;
die "Usage: version::vcmp(lobj, robj, ...)" if @_ < 2;
Expand Down
33 changes: 33 additions & 0 deletions vutil/vxs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
{VXS_CLASS "::(0+", VXSp(version_numify), VXSXSDP(NULL)},
{VXS_CLASS "::numify", VXSp(version_numify), VXSXSDP(NULL)},
{VXS_CLASS "::normal", VXSp(version_normal), VXSXSDP(NULL)},
{VXS_CLASS "::to_decimal", VXSp(version_to_decimal), VXSXSDP(NULL)},
{VXS_CLASS "::to_dotted_decimal", VXSp(version_to_dotted_decimal), VXSXSDP(NULL)},
{VXS_CLASS "::(cmp", VXSp(version_vcmp), VXSXSDP(NULL)},
{VXS_CLASS "::(<=>", VXSp(version_vcmp), VXSXSDP(NULL)},
# ifdef PERL_CORE
Expand Down Expand Up @@ -296,6 +298,37 @@ VXS(version_normal)
}
}

VXS(version_to_decimal)
{
dXSARGS;
SV* self = ST(0);
if (items < 1)
croak_xs_usage(cv, "lobj, ...");
SP -= items;
{
SV *lobj, *rv;
VTYPECHECK(lobj, self, "lobj");
rv = NEW_VERSION(VNUMIFY(lobj));
VXS_RETURN_M_SV(sv_bless(rv, SvSTASH(SvRV(self))));
}
}

VXS(version_to_dotted_decimal)
{
dXSARGS;
SV* self = ST(0);
if (items != 1)
croak_xs_usage(cv, "ver");
SP -= items;
{
SV *lobj, *rv;
VTYPECHECK(lobj, self, "lobj");
rv = NEW_VERSION(VNORMAL(lobj));
sv_bless(rv, SvSTASH(SvRV(self)));
VXS_RETURN_M_SV(sv_bless(rv, SvSTASH(SvRV(self))));
}
}

VXS(version_vcmp)
{
dXSARGS;
Expand Down

0 comments on commit bd54c16

Please sign in to comment.