]> Dogcows Code - chaz/p5-File-KDBX/commitdiff
Fix test fail with older versions of Time::Piece
authorCharles McGarvey <ccm@cpan.org>
Tue, 3 May 2022 22:27:30 +0000 (16:27 -0600)
committerCharles McGarvey <ccm@cpan.org>
Wed, 4 May 2022 01:17:39 +0000 (19:17 -0600)
lib/File/KDBX/Util.pm
t/entry.t
t/util.t

index 62515f53300bcf8c430514fc6c074ebf8aafb36f..84cb363158b50b14125e970052a0e0244afa6108 100644 (file)
@@ -598,7 +598,7 @@ sub pack_Ql {
     my $num = shift;
     require Config;
     if ($Config::Config{ivsize} < 8) {
-        if (blessed $num && $num->can('to_hex')) {
+        if (blessed $num && $num->can('as_hex')) {
             return "\xff\xff\xff\xff\xff\xff\xff\xff" if Math::BigInt->new('18446744073709551615') <= $num;
             return "\x00\x00\x00\x00\x00\x00\x00\x80" if $num <= Math::BigInt->new('-9223372036854775808');
             my $neg;
@@ -606,7 +606,9 @@ sub pack_Ql {
                 $neg = 1;
                 $num = -$num;
             }
-            my $bytes = reverse pack('H16', substr(('0' x 15) . $num->to_hex, -16));
+            my $hex = $num->as_hex;
+            $hex =~ s/^0x/000000000000000/;
+            my $bytes = reverse pack('H16', substr($hex, -16));
             $bytes .= "\0" x (8 - length $bytes) if length $bytes < 8;
             if ($neg) {
                 # two's compliment
@@ -646,7 +648,7 @@ sub unpack_Ql {
     require Config;
     if ($Config::Config{ivsize} < 8) {
         require Math::BigInt;
-        return (Math::BigInt->new('0x' . unpack('H*', scalar reverse $bytes)));
+        return Math::BigInt->new('0x' . unpack('H*', scalar reverse $bytes));
     }
     return unpack('Q<', $bytes);
 }
@@ -665,14 +667,14 @@ sub unpack_ql {
     if ($Config::Config{ivsize} < 8) {
         require Math::BigInt;
         if (ord(substr($bytes, -1, 1)) & 128) {
-            return (Math::BigInt->new('-9223372036854775808')) if $bytes eq "\x00\x00\x00\x00\x00\x00\x00\x80";
+            return Math::BigInt->new('-9223372036854775808') if $bytes eq "\x00\x00\x00\x00\x00\x00\x00\x80";
             # two's compliment
             substr($bytes, 0, 1, chr(ord(substr($bytes, 0, 1)) - 1));
             $bytes = join('', map { chr(~ord($_) & 0xff) } split(//, $bytes));
-            return (-Math::BigInt->new('0x' . unpack('H*', scalar reverse $bytes)));
+            return -Math::BigInt->new('0x' . unpack('H*', scalar reverse $bytes));
         }
         else {
-            return (Math::BigInt->new('0x' . unpack('H*', scalar reverse $bytes)));
+            return Math::BigInt->new('0x' . unpack('H*', scalar reverse $bytes));
         }
     }
     return unpack('q<', $bytes);
index f08b683036af4f71eed1d627bde8149a31c660a7..1581608520220b84ba71f530c6008d0922ab08e1 100644 (file)
--- a/t/entry.t
+++ b/t/entry.t
@@ -82,7 +82,7 @@ subtest 'Accessors' => sub {
     my $entry = File::KDBX::Entry->new;
 
     $entry->creation_time('2022-02-02 12:34:56');
-    cmp_ok $entry->creation_time, '==', 1643805296, 'Creation time coerced into a Time::Piece (epoch)';
+    cmp_ok $entry->creation_time->epoch, '==', 1643805296, 'Creation time coerced into a Time::Piece (epoch)';
     is $entry->creation_time->datetime, '2022-02-02T12:34:56', 'Creation time coerced into a Time::Piece';
 };
 
index 5c26c9d3d5fb4471e66827a052200cefacd0a5c6..a785b2f7ce1c7dde8f51b270f59474e153daa1d7 100644 (file)
--- a/t/util.t
+++ b/t/util.t
@@ -7,7 +7,7 @@ use lib 't/lib';
 use TestCommon;
 
 use File::KDBX::Util qw(:all);
-use Math::BigInt 1.999808;
+use Math::BigInt;
 use Scalar::Util qw(blessed);
 use Test::More;
 
This page took 0.02458 seconds and 4 git commands to generate.