mirror of
https://codeberg.org/scip/Crypt--PWSafe3.git
synced 2025-12-17 04:31:00 +01:00
internal records now associated with parent
This commit is contained in:
@@ -31,7 +31,7 @@ use Data::Dumper;
|
||||
use Exporter ();
|
||||
use vars qw(@ISA @EXPORT);
|
||||
|
||||
$Crypt::PWSafe3::VERSION = '1.21';
|
||||
$Crypt::PWSafe3::VERSION = '1.22';
|
||||
|
||||
use Crypt::PWSafe3::Field;
|
||||
use Crypt::PWSafe3::HeaderField;
|
||||
@@ -281,7 +281,7 @@ sub read {
|
||||
}
|
||||
|
||||
# read db records
|
||||
my $record = Crypt::PWSafe3::Record->new();
|
||||
my $record = Crypt::PWSafe3::Record->new(super => $this);
|
||||
$this->{record} = {};
|
||||
while (1) {
|
||||
my $field = $this->readfield();
|
||||
@@ -290,7 +290,7 @@ sub read {
|
||||
}
|
||||
if ($field->type == 0xff) {
|
||||
$this->addrecord($record);
|
||||
$record = Crypt::PWSafe3::Record->new();
|
||||
$record = Crypt::PWSafe3::Record->new(super => $this);
|
||||
}
|
||||
else {
|
||||
$record->addfield($field);
|
||||
@@ -589,6 +589,7 @@ sub newrecord {
|
||||
}
|
||||
$this->markmodified();
|
||||
$this->addrecord($record);
|
||||
$this->{records}->{$record->uuid}->{super} = $this;
|
||||
return $record->uuid;
|
||||
}
|
||||
|
||||
@@ -859,16 +860,21 @@ which is a unique identifier. You can access the uuid by:
|
||||
Accessing other record properties works the same. For
|
||||
more details, refer to L<Crypt::PWSafe3::Record>.
|
||||
|
||||
Please note that record objects accessed this way are
|
||||
copies. If you change such a record object and save the
|
||||
database, nothing will in fact change. In this case you
|
||||
need to put the changed record back into the record
|
||||
list of the Crypt::PWSafe3 object by:
|
||||
B<Note>: record objects returned by getrecords() are
|
||||
still associated with the L<Crypt::PWSafe3> object. So,
|
||||
if you modify a field of such a record, the change will
|
||||
be populated back into the vault. Of course you'd still
|
||||
need to save it.
|
||||
|
||||
$vault->addrecord($record):
|
||||
Sample:
|
||||
|
||||
See section L<addrecord()> for more details on this.
|
||||
foreach my $rec ($vault->getrecords) {
|
||||
$rec->note('blah fasel');
|
||||
}
|
||||
$vault->save();
|
||||
|
||||
However, it's also possible to use the B<modifyrecord()>
|
||||
method, see below.
|
||||
|
||||
=head2 B<looprecord()>
|
||||
|
||||
@@ -998,7 +1004,7 @@ License 2.0, see: L<http://www.perlfoundation.org/artistic_license_2_0>
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
Crypt::PWSafe3 Version 1.21.
|
||||
Crypt::PWSafe3 Version 1.22.
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ my %map2type = %Crypt::PWSafe3::Field::map2type;
|
||||
|
||||
my %map2name = %Crypt::PWSafe3::Field::map2name;
|
||||
|
||||
$Crypt::PWSafe3::Record::VERSION = '1.09';
|
||||
$Crypt::PWSafe3::Record::VERSION = '1.10';
|
||||
|
||||
foreach my $field (keys %map2type ) {
|
||||
eval qq(
|
||||
@@ -34,9 +34,9 @@ foreach my $field (keys %map2type ) {
|
||||
sub new {
|
||||
#
|
||||
# new record object
|
||||
my($this) = @_;
|
||||
my($this, %param) = @_;
|
||||
my $class = ref($this) || $this;
|
||||
my $self = { };
|
||||
my $self = \%param;
|
||||
bless($self, $class);
|
||||
$self->{field} = ();
|
||||
|
||||
@@ -123,6 +123,35 @@ sub modifyfield {
|
||||
name => "lastmod",
|
||||
value => $time
|
||||
));
|
||||
|
||||
my ($package, $filename, $line, $subroutine, @ignore) = caller(1);
|
||||
|
||||
# this looks a little bit weird but it's a cool feat.
|
||||
# 'super' contains the vault object (of class Crypt::PWSafe3),
|
||||
# which initially called our new() method, so we know to which
|
||||
# vault we belong.
|
||||
# therefore, if the user just calls $record->passwd('newpw'),
|
||||
# then we can update the record directly on the vault object,
|
||||
# so that the user doesn't have to call modifyrecord. this is
|
||||
# especially usefull inside a loop.
|
||||
# also note, that the 'super' parameter to Crypt::PWSafe3::Record::new()
|
||||
# is not documented, so it's an internal parameter not to be used
|
||||
# by users. however, maybe in the future it would be useful to
|
||||
# have it populated so that if a user has a function which takes a
|
||||
# record as parameter, then in this function he could access the
|
||||
# vault as well. maybe.
|
||||
#
|
||||
# Thu May 21 10:04:15 CEST 2015 tlinden\@cpan.org
|
||||
if (exists $this->{super} &&
|
||||
"${package}::${subroutine}" !~ /Crypt::PWSafe3::modifyrecord$/ &&
|
||||
"${package}::${subroutine}" !~ /Crypt::PWSafe3::newrecord$/ &&
|
||||
"${package}::${subroutine}" !~ /Crypt::PWSafe3::Record::modifyfield$/
|
||||
) {
|
||||
# we've been called from the outside (the user in fact) and
|
||||
# we're attached to a vault, so update ourselfes there as well
|
||||
$this->{super}->modifyrecord($this->uuid, $name, $value);
|
||||
}
|
||||
|
||||
return $field;
|
||||
}
|
||||
else {
|
||||
@@ -189,6 +218,12 @@ It is also possible to access the raw unencoded values of the fields
|
||||
by accessing them directly, refer to L<Crypt::PWSafe3::Field> for more
|
||||
details on this.
|
||||
|
||||
If the record object has been created by L<Crypt::PWSafe3> (and fetched with
|
||||
Crypt::PWSafe3::getrecord), then it's still associated with the L<Crypt::PWSafe3>
|
||||
parent object. Changes to the record will therefore automatically populated
|
||||
back into the parent object (the vault). This is not the case if you created
|
||||
the record object yourself.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 B<uuid([string])>
|
||||
|
||||
Reference in New Issue
Block a user