]> Dogcows Code - chaz/p5-File-KDBX/blobdiff - lib/File/KDBX/IO/HmacBlock.pm
Add function for creating class attributes
[chaz/p5-File-KDBX] / lib / File / KDBX / IO / HmacBlock.pm
index ac07e7e474bb6f5688feee516f2042c03daab7eb..50f054ba2d09fb810deb49cbbdad7b7520f164ac 100644 (file)
@@ -8,37 +8,15 @@ use Crypt::Digest qw(digest_data);
 use Crypt::Mac::HMAC qw(hmac);
 use Errno;
 use File::KDBX::Error;
-use File::KDBX::Util qw(:io assert_64bit);
+use File::KDBX::Util qw(:class :io assert_64bit);
 use namespace::clean;
 
-use parent 'File::KDBX::IO';
+extends 'File::KDBX::IO';
 
 our $VERSION = '999.999'; # VERSION
 our $BLOCK_SIZE = 1048576;  # 1MiB
 our $ERROR;
 
-=method new
-
-    $fh = File::KDBX::IO::HmacBlock->new(%attributes);
-    $fh = File::KDBX::IO::HmacBlock->new($fh, %attributes);
-
-Construct a new HMAC-block stream IO handle.
-
-=cut
-
-sub new {
-    assert_64bit;
-
-    my $class = shift;
-    my %args = @_ % 2 == 1 ? (fh => shift, @_) : @_;
-    my $self = $class->SUPER::new;
-    $self->_fh($args{fh}) or throw 'IO handle required';
-    $self->key($args{key}) or throw 'Key required';
-    $self->block_size($args{block_size});
-    $self->_buffer;
-    return $self;
-}
-
 =attr block_size
 
 Desired block size when writing (default: C<$File::KDBX::IO::HmacBlock::BLOCK_SIZE> or 1,048,576 bytes)
@@ -51,7 +29,7 @@ HMAC-SHA256 key for authenticating the data stream (required)
 
 my %ATTRS = (
     _block_index    => 0,
-    _buffer         => \(my $buf = ''),
+    _buffer         => sub { \(my $buf = '') },
     _finished       => 0,
     block_size      => sub { $BLOCK_SIZE },
     key             => undef,
@@ -65,6 +43,28 @@ while (my ($attr, $default) = each %ATTRS) {
     };
 }
 
+=method new
+
+    $fh = File::KDBX::IO::HmacBlock->new(%attributes);
+    $fh = File::KDBX::IO::HmacBlock->new($fh, %attributes);
+
+Construct a new HMAC-block stream IO handle.
+
+=cut
+
+sub new {
+    assert_64bit;
+
+    my $class = shift;
+    my %args = @_ % 2 == 1 ? (fh => shift, @_) : @_;
+    my $self = $class->SUPER::new;
+    $self->_fh($args{fh}) or throw 'IO handle required';
+    $self->key($args{key}) or throw 'Key required';
+    $self->block_size($args{block_size});
+    $self->_buffer;
+    return $self;
+}
+
 sub _FILL {
     my ($self, $fh) = @_;
 
This page took 0.022022 seconds and 4 git commands to generate.