]> Dogcows Code - chaz/p5-File-KDBX/blobdiff - lib/File/KDBX/IO/HashBlock.pm
Add function for creating class attributes
[chaz/p5-File-KDBX] / lib / File / KDBX / IO / HashBlock.pm
index adb1cc6f28e60f7fc36c76bbb2328675fabd38c6..f4ab8b6fba9ab1e36e66135e4b6275a0716dd13e 100644 (file)
@@ -7,37 +7,17 @@ use strict;
 use Crypt::Digest qw(digest_data);
 use Errno;
 use File::KDBX::Error;
-use File::KDBX::Util qw(:io);
+use File::KDBX::Util qw(:class :io);
 use IO::Handle;
 use namespace::clean;
 
-use parent 'File::KDBX::IO';
+extends 'File::KDBX::IO';
 
 our $VERSION = '999.999'; # VERSION
 our $ALGORITHM = 'SHA256';
 our $BLOCK_SIZE = 1048576;  # 1MiB
 our $ERROR;
 
-=method new
-
-    $fh = File::KDBX::IO::HashBlock->new(%attributes);
-    $fh = File::KDBX::IO::HashBlock->new($fh, %attributes);
-
-Construct a new hash-block stream IO handle.
-
-=cut
-
-sub new {
-    my $class = shift;
-    my %args = @_ % 2 == 1 ? (fh => shift, @_) : @_;
-    my $self = $class->SUPER::new;
-    $self->_fh($args{fh}) or throw 'IO handle required';
-    $self->algorithm($args{algorithm});
-    $self->block_size($args{block_size});
-    $self->_buffer;
-    return $self;
-}
-
 =attr algorithm
 
 Digest algorithm in hash-blocking the stream (default: C<SHA-256>)
@@ -50,7 +30,7 @@ Desired block size when writing (default: C<$File::KDBX::IO::HashBlock::BLOCK_SI
 
 my %ATTRS = (
     _block_index    => 0,
-    _buffer         => \(my $buf = ''),
+    _buffer         => sub { \(my $buf = '') },
     _finished       => 0,
     algorithm       => sub { $ALGORITHM },
     block_size      => sub { $BLOCK_SIZE },
@@ -64,6 +44,26 @@ while (my ($attr, $default) = each %ATTRS) {
     };
 }
 
+=method new
+
+    $fh = File::KDBX::IO::HashBlock->new(%attributes);
+    $fh = File::KDBX::IO::HashBlock->new($fh, %attributes);
+
+Construct a new hash-block stream IO handle.
+
+=cut
+
+sub new {
+    my $class = shift;
+    my %args = @_ % 2 == 1 ? (fh => shift, @_) : @_;
+    my $self = $class->SUPER::new;
+    $self->_fh($args{fh}) or throw 'IO handle required';
+    $self->algorithm($args{algorithm});
+    $self->block_size($args{block_size});
+    $self->_buffer;
+    return $self;
+}
+
 sub _FILL {
     my ($self, $fh) = @_;
 
This page took 0.021714 seconds and 4 git commands to generate.