New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
making $^V a version object broke functionality #15488
Comments
From @maukeCreated by @maukeperldoc perl5100delta: | $^V is now a "version" object instead of a v-string OK, they must be rewritten. But how? Consider e.g. printf "use feature ':%vd';\n", substr($^V, 0, 2); This is reasonable code with v-strings. How do you do the same thing with a As far as I can see, the version module only provides parsing, pretty-printing, The 5.10 change removed functionality, telling us that the 5.6/5.8 way no As an aside, perldoc -v '$^V' says: | The disadvantage is that prior to v5.10.0, it was only a literal v-string, Which doesn't have any technical basis: You could easily print it using Perl Info
|
From @JohnPeacockOn 07/31/2016 10:04 AM, l.mai@web.de wrote:
Perl objects are typically just hashes of stuff, blessed into a class, e.g. $ perl -w -MData::Dumper -E 'say Dumper($^V);' So your code could be rewritten as: printf "use feature ':%d.$d;\n", @{$^V->{version}}[0,1]; v-strings are intrinsically a binary format, so you MUST treat it If you'd like to open a feature request for version.pm to include Thanks John |
The RT System itself - Status changed from 'new' to 'open' |
From @maukeAm 31.07.2016 um 17:48 schrieb John Peacock:
That's not part of the public API. I'd have to rely on implementation Can this code be written at all using just the public API and without
1. v-strings are normal scalars: they're strings.
I'm not directly concerned with version.pm. I've never had a use for it. My main concern is being able to introspect the version number of the In that case a method to return the numeric components would be nice, as my @parts = $^V->parts; # (5, 24, 0) Would that be good addition to the version.pm API? -- |
From zefram@fysh.orgLukas Mai wrote:
$] has always worked for that, and still does. @parts = map { 0+$_ } sprintf("%010.6f", "$]") =~ /([0-9]{3})/g; -zefram |
From @JohnPeacockOn 07/31/2016 03:46 PM, Lukas Mai wrote:
Actually, the internal representation *is* part of the public API, see
I beg to differ. v-strings are stored as simple scalar but they are an ENQ CAN NUL You cannot print a v-string without the special "%vd" format, which $ perl -MDevel::Peek -E 'say Dump(53.56.48)'
While this is true, it is also misleading, in that you had to already
Then frankly you are using the version module wrong. A version object
The fact that the normal stringification method of version objects is to
Attached is a proposed addition to the public API that provides the use version; before you can use any of these methods. If this would fit your needs, John |
From @JohnPeacockelements.diffdiff -r ba402aa3d3a5 lib/version.pm
--- a/lib/version.pm Wed Aug 03 05:22:30 2016 -0400
+++ b/lib/version.pm Wed Aug 03 06:31:20 2016 -0400
@@ -124,5 +124,36 @@
}
}
+# Helper methods
+sub elements {
+ my ($self) = @_;
+ return ($self->{version});
+}
+sub epoch {
+ my ($self) = @_;
+ my @elements = @{$self->elements};
+ return 'v'.$elements[0];
+}
+
+sub major {
+ my ($self) = @_;
+ my @elements = @{$self->elements};
+ push @elements, 0 while $#elements < 2;
+ return 'v'.join('.', @elements[0,1]);
+}
+
+sub minor {
+ my ($self) = @_;
+ my @elements = @{$self->elements};
+ push @elements, 0 while $#elements < 3;
+ return 'v'.join('.', @elements[0,1,2]);
+}
+
+sub patch {
+ my ($self) = @_;
+ my @elements = @{$self->elements};
+ push @elements, 0 while $#elements < 4;
+ return 'v'.join('.', @elements[0,1,2,3]);
+}
1;
|
From @maukeAm 03.08.2016 um 12:39 schrieb John Peacock:
Wait, version::Internals is supposed to be a public API? You definitely need to document that, then. When something is called Case in point: the $v->{version} field is described in a document called All of this screams "DO NOT USE" (outside of debugging) to me.
Again, this should be documented, then. Neither version nor (Besides, I'd have to rebless $^V, which is a whole nother can of worms.)
I find the current situation even more confusing. "v-strings are just
I'm not using the version module (directly). I'm using the $^V variable, A few days ago I had to (for the first time) do something with perl
($] works fine for fixed values. Why bother with an object then?) My actual use case is this: I have a project (stored in a single My solution was to create a wrapper module that adds a version-dependent Further constraints: I want the subdirectory names to look nice for A while later I came across a second use case: Create a dynamic script Both of these are easy with v-strings: sprintf('v%vd', substr($v, 0, 2))
You seem to have a (harmless) off-by-one error in there: You do 'push The other issue I see is that the methods and names are specific to $^V, Finally, the epoch/major/minor/patch methods form yet another I like 'elements' but from the name I would've expected it to return a -- |
From @maukeAm 01.08.2016 um 08:38 schrieb Zefram:
I think that's borderline obfuscated. The biggest WTF in there is "$]": Also, that still counts as reparsing a pretty-printed form. If I wanted @parts = $^V =~ /\d+/g; (which silently fails in 5.6 and 5.8) or @parts = sprintf("%vd", $^V) =~ /\d+/g; (for compatibility). -- |
From zefram@fysh.orgLukas Mai wrote:
It's arcane, yes. But reliable.
To work around [perl #72210].
The sprintf standardises the pattern of digits into what's needed for -zefram |
From @ap* Lukas Mai <plokinom@gmail.com> [2016-07-31 21:48]:
Just use The only annoyance you might have is that you get '5.022001' instead of However, don’t listen to this: * Zefram <zefram@fysh.org> [2016-08-01 08:48]:
… because $] is not a float, and you get in trouble (that the manual $ perl -MDevel::Peek -e 'Dump $]' It’s a string. And always has been. Treat it that way and it will treat @parts = map 0+$_, $] =~ /\A(\d+)\.(\d{3})(\d{3})\z/gaa; But for your stated main concern, I would instead go with printf "use feature ':5.%d';\n", substr $], 2, 3; That’s about as simple as anything gets, aye? Regards, |
From zefram@fysh.orgAristotle Pagaltzis wrote:
No, it's not of that form on every version. On 5.8.0 it's "5.008", -zefram |
From @JohnPeacockOn 08/03/2016 03:49 PM, Lukas Mai wrote:
The version::Internals text originally was part of the main POD and I I actually test the ability to subclass version.pm part of the So here is an example subclass just for you: package vversion; sub vstring { 1; Call it like this: $ perl -I. -Mvversion -MDevel::Peek -E \ SV = PVMG(0x15ee440) at 0x1625c68 That gets you the vstring that you can do anything you want with. In $ perl -MDevel::Peek -E \ SV = PVMG(0x247d920) at 0x24b4c68 Since you seem to be primarily interested in the value of $^V, you can $ perl -MDevel::Peek -E '$v = eval("$^V"); say Dump($v);' All things considered, I think this is not something that absolutely John |
Migrated from rt.perl.org#128786 (status was 'open')
Searchable as RT128786$
The text was updated successfully, but these errors were encountered: