KDBX/Group.pm

filter: Statementstmt 89.1% 305 / 342 Branchbran 66.3% 126 / 190 Conditioncond 63.9% 78 / 122 MC/DCmcdc 39.1% 29 / 74 Subroutinesub 88.0% 66 / 75 Podpod 97.7% 43 / 44 totaltotal 76.3% 647 / 847 CC 145 SCAR 16.6
CC
145
Cov
78%
depth
20.0
effective_default_auto_type_sequence
12.0
is_entry_templates
12.0
CRAP 5.3
« KDBX/IO/Crypt.pm ↑ Summary KDBX/Cipher/Stream.pm »
1 package File::KDBX::Group;
2 # ABSTRACT: A KDBX database group
3  
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 10 ▶use Devel::GlobalDestruction;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use File::KDBX::Constants qw(:bool :icon :iteration);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use File::KDBX::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use File::KDBX::Iterator;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 10 ▶use File::KDBX::Util qw(:assert :class :coercion generate_uuid);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶use Hash::Util::FieldHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 10 ▶use List::Util qw(any sum0);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 10 ▶use Ref::Util qw(is_coderef is_ref);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 10 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 10 ▶use Time::Piece 1.33;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 10 ▶use boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 10 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 10 extends 'File::KDBX::Object';
21  
22 10 our $VERSION = '0.905'; # VERSION
23 230 ▶ 
Subroutine name: called CC=4 SCAR=14.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_[0]) 0 230 230
24 230 ▶ 
Subroutine notes: called CC=4 SCAR=14.1
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 86 144 230
unless builtin::blessed($_[0]) 0 149 149
25 230 ▶# has uuid => sub { generate_uuid(printable => 1) };
Subroutine tags: called CC=4 SCAR=14.1
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 63 86 149
unless builtin::blessed($_[0]) 0 237 237
Condition66%2/3
$_[0]{"name"} //= $default
l!l&&r!l&&!r
22406
MC/DC50%1/2
$_[0]{"name"} //= $default
$_[0]{"name"} $default
Truth table66%2/3
A //= B
A= $_[0]{"name"}B= $default
ABresult
1X1
011
000
26 149 ▶has name => '', coerce => \&to_string;
Subroutine icon_id: called CC=4 SCAR=14.2
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 2 235 237
unless builtin::blessed($_[0]) 0 103 103
Condition66%2/3
$_[0]{"notes"} //= $default
l!l&&r!l&&!r
131018
MC/DC50%1/2
$_[0]{"notes"} //= $default
$_[0]{"notes"} $default
Truth table66%2/3
A //= B
A= $_[0]{"notes"}B= $default
ABresult
1X1
011
000
27 237 ▶has notes => '', coerce => \&to_string;
Subroutine custom_icon_uuid: called CC=4 SCAR=14.3
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 18 85 103
unless builtin::blessed($_[0]) 0 88 88
Condition66%2/3
$_[0]{"tags"} //= $default
l!l&&r!l&&!r
150087
MC/DC50%1/2
$_[0]{"tags"} //= $default
$_[0]{"tags"} $default
Truth table66%2/3
A //= B
A= $_[0]{"tags"}B= $default
ABresult
1X1
011
000
28 103 ▶has tags => '', coerce => \&to_string;
Subroutine is_expanded: called CC=4 SCAR=14.5
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 0 88 88
unless builtin::blessed($_[0]) 0 148 148
Condition66%2/3
$_[0]{"icon_id"} //= $default
l!l&&r!l&&!r
24790
MC/DC0%0/2
$_[0]{"icon_id"} //= $default
$_[0]{"icon_id"} $default
Truth table66%2/3
A //= B
A= $_[0]{"icon_id"}B= $default
ABresult
1X1
011
000
29 88 ▶has icon_id => ICON_FOLDER, coerce => \&to_icon_constant;
Subroutine default_auto_type_sequence: called CC=4 SCAR=14.3
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 62 86 148
unless builtin::blessed($_[0]) 0 84 84
Condition50%1/2
$_[0]{"custom_icon_uuid"} //= undef
l!l
088
MC/DC0%0/1
$_[0]{"custom_icon_uuid"} //= undef
$_[0]{"custom_icon_uuid"}
Truth table50%1/2
A
A= $_[0]{"custom_icon_uuid"}
Aresult
11
00
30 148 ▶has custom_icon_uuid => undef, coerce => \&to_uuid;
Subroutine enable_auto_type: called CC=4 SCAR=14.1
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 0 84 84
unless builtin::blessed($_[0]) 0 85 85
Condition66%2/3
$_[0]{"is_expanded"} //= $default
l!l&&r!l&&!r
130018
MC/DC50%1/2
$_[0]{"is_expanded"} //= $default
$_[0]{"is_expanded"} $default
Truth table66%2/3
A //= B
A= $_[0]{"is_expanded"}B= $default
ABresult
1X1
011
000
31 84 ▶has is_expanded => false, coerce => \&to_bool;
Subroutine enable_searching: called CC=4 SCAR=14.0
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 1 84 85
unless builtin::blessed($_[0]) 0 86 86
Condition66%2/3
$_[0]{"default_auto_type_sequence"} //= $default
l!l&&r!l&&!r
4080
MC/DC50%1/2
$_[0]{"default_auto_type_sequence"} //= $default
$_[0]{"default_auto_type_sequence"} $default
Truth table66%2/3
A //= B
A= $_[0]{"default_auto_type_sequence"}B= $default
ABresult
1X1
011
000
32 85 ▶has default_auto_type_sequence => '', coerce => \&to_string;
Subroutine last_top_visible_entry: called CC=4 SCAR=14.0
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 1 85 86
unless builtin::blessed($_[0]) 0 80 80
Condition100%2/2
$_[0]{"enable_auto_type"} //= undef
l!l
382
MC/DC100%1/1
$_[0]{"enable_auto_type"} //= undef
$_[0]{"enable_auto_type"}
Truth table100%2/2
A
A= $_[0]{"enable_auto_type"}
Aresult
11
00
33 86 ▶has enable_auto_type => undef, coerce => \&to_tristate;
Branch: 1 branch
BranchTrueFalseTotal
if $#_ 0 80 80
Condition100%2/2
$_[0]{"enable_searching"} //= undef
l!l
482
MC/DC100%1/1
$_[0]{"enable_searching"} //= undef
$_[0]{"enable_searching"}
Truth table100%2/2
A
A= $_[0]{"enable_searching"}
Aresult
11
00
34 80 ▶has enable_searching => undef, coerce => \&to_tristate;
Subroutine previous_parent_group: called CC=4 SCAR=14.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_[0]) 0 238 238
Condition50%1/2
$_[0]{"last_top_visible_entry"} //= undef
l!l
080
MC/DC0%0/1
$_[0]{"last_top_visible_entry"} //= undef
$_[0]{"last_top_visible_entry"}
Truth table50%1/2
A
A= $_[0]{"last_top_visible_entry"}
Aresult
11
00
35 238 ▶has last_top_visible_entry => undef, coerce => \&to_uuid;
Branch: 1 branch
BranchTrueFalseTotal
if $#_ 2 236 238
36 238 ▶# has custom_data => {};
Condition100%2/2
$_[0]{"previous_parent_group"} //= undef
l!l
2236
MC/DC100%1/1
$_[0]{"previous_parent_group"} //= undef
$_[0]{"previous_parent_group"}
Truth table100%2/2
A
A= $_[0]{"previous_parent_group"}
Aresult
11
00
37 668 ▶has previous_parent_group => undef, coerce => \&to_uuid;
Subroutine times: called CC=4 SCAR=14.3
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_[0]) 0 668 668
38 668 ▶# has entries => [];
Branch: 1 branch
BranchTrueFalseTotal
if $#_ 0 668 668
39 668 ▶# has groups => [];
Subroutine last_modification_time: called CC=4 SCAR=14.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_[0]) 0 86 86
Condition100%2/2
$_[0]{"times"} //= scalar &$default($_[0])
l!l
58880
MC/DC100%1/1
$_[0]{"times"} //= scalar &$default($_[0])
$_[0]{"times"}
Truth table100%2/2
A
A= $_[0]{"times"}
Aresult
11
00
40 86 ▶has times => {};
Subroutine creation_time: called CC=4 SCAR=14.1
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 6 80 86
unless builtin::blessed($_[0]) 0 80 80
41 86 ▶ 
Subroutine last_access_time: called CC=4 SCAR=14.1
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 0 80 80
unless builtin::blessed($_[0]) 0 86 86
Condition100%2/2
$_[0]->times->{"last_modification_time"} //= scalar &$default($_[0])
l!l
680
MC/DC100%1/1
$_[0]->times->{"last_modification_time"} //= scalar &$default($_[0])
$_[0]->times->{"last_modification_time"}
Truth table100%2/2
A
A= $_[0]->times->{"last_modification_time"}
Aresult
11
00
42 80 ▶has last_modification_time => sub { gmtime }, store => 'times', coerce => \&to_time;
Subroutine __ANON__: called CC=1 SCAR=0.1
Subroutine expiry_time: called CC=4 SCAR=14.2
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 6 80 86
unless builtin::blessed($_[0]) 0 80 80
Condition50%1/2
$_[0]->times->{"creation_time"} //= scalar &$default($_[0])
l!l
080
MC/DC0%0/1
$_[0]->times->{"creation_time"} //= scalar &$default($_[0])
$_[0]->times->{"creation_time"}
Truth table50%1/2
A
A= $_[0]->times->{"creation_time"}
Aresult
11
00
43 86 ▶has creation_time => sub { gmtime }, store => 'times', coerce => \&to_time;
Subroutine __ANON__: called CC=1 SCAR=0.1
Subroutine expires: called CC=4 SCAR=14.4
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 0 80 80
unless builtin::blessed($_[0]) 0 84 84
Condition100%2/2
$_[0]->times->{"last_access_time"} //= scalar &$default($_[0])
l!l
680
MC/DC100%1/1
$_[0]->times->{"last_access_time"} //= scalar &$default($_[0])
$_[0]->times->{"last_access_time"}
Truth table100%2/2
A
A= $_[0]->times->{"last_access_time"}
Aresult
11
00
44 80 ▶has last_access_time => sub { gmtime }, store => 'times', coerce => \&to_time;
Subroutine __ANON__: called CC=1 SCAR=0.2
Subroutine usage_count: called CC=4 SCAR=14.8
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 0 84 84
unless builtin::blessed($_[0]) 0 80 80
Condition50%1/2
$_[0]->times->{"expiry_time"} //= scalar &$default($_[0])
l!l
080
MC/DC0%0/1
$_[0]->times->{"expiry_time"} //= scalar &$default($_[0])
$_[0]->times->{"expiry_time"}
Truth table50%1/2
A
A= $_[0]->times->{"expiry_time"}
Aresult
11
00
45 84 ▶has expiry_time => sub { gmtime }, store => 'times', coerce => \&to_time;
Subroutine __ANON__: called CC=1 SCAR=0.2
Subroutine location_changed: called CC=4 SCAR=14.8
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 0 80 80
unless builtin::blessed($_[0]) 0 80 80
Condition66%2/3
$_[0]->times->{"expires"} //= $default
l!l&&r!l&&!r
4080
MC/DC50%1/2
$_[0]->times->{"expires"} //= $default
$_[0]->times->{"expires"} $default
Truth table66%2/3
A //= B
A= $_[0]->times->{"expires"}B= $default
ABresult
1X1
011
000
46 80 ▶has expires => false, store => 'times', coerce => \&to_bool;
Branch: 1 branch
BranchTrueFalseTotal
if $#_ 0 80 80
Condition33%1/3
$_[0]->times->{"usage_count"} //= $default
l!l&&r!l&&!r
0080
MC/DC0%0/2
$_[0]->times->{"usage_count"} //= $default
$_[0]->times->{"usage_count"} $default
Truth table33%1/3
A //= B
A= $_[0]->times->{"usage_count"}B= $default
ABresult
1X1
011
000
47 80 ▶has usage_count => 0, store => 'times', coerce => \&to_number;
Condition50%1/2
$_[0]->times->{"location_changed"} //= scalar &$default($_[0])
l!l
080
MC/DC0%0/1
$_[0]->times->{"location_changed"} //= scalar &$default($_[0])
$_[0]->times->{"location_changed"}
Truth table50%1/2
A
A= $_[0]->times->{"location_changed"}
Aresult
11
00
48 80 ▶has location_changed => sub { gmtime }, store => 'times', coerce => \&to_time;
Subroutine __ANON__: called CC=1 SCAR=0.0
49  
50 10 my @ATTRS = qw(uuid custom_data entries groups);
51 sub _set_nonlazy_attributes {
52 80 ▶ my $self = shift;
Subroutine _set_nonlazy_attributes: called CC=2 SCAR=6.9
53 80 $self->$_ for @ATTRS, list_attributes(ref $self);
54 }
55  
56 sub uuid {
57 273 ▶ my $self = shift;
Subroutine uuid: called CC=6 SCAR=17.9
Pod documented
58 273 ▶ if (@_ || !defined $self->{uuid}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ or not defined $self->{"uuid"}) 81 192 273
Condition100%3/3
@_ or not defined $self->{"uuid"}
l!l&&r!l&&!r
180192
MC/DC100%2/2
@_ or not defined $self->{"uuid"}
@_ not defined $self->{"uuid"}
Truth table100%3/3
A or not(B)
A= @_B= not defined $self->{"uuid"}
ABresult
1X1
011
000
59 81 ▶ my %args = @_ % 2 == 1 ? (uuid => shift, @_) : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 == 1 ? : 1 80 81
60 81 my $old_uuid = $self->{uuid};
61 81 ▶ my $uuid = $self->{uuid} = delete $args{uuid} // generate_uuid;
Condition66%2/3
delete $args{"uuid"} // generate_uuid()
l!l&&r!l&&!r
1800
MC/DC0%0/2
delete $args{"uuid"} // generate_uuid()
delete $args{"uuid"} generate_uuid()
Truth table66%2/3
A // B
A= delete $args{"uuid"}B= generate_uuid()
ABresult
1X1
011
000
62 81 ▶ $self->_signal('uuid.changed', $uuid, $old_uuid) if defined $old_uuid;
Branch: 1 branch
BranchTrueFalseTotal
if defined $old_uuid 1 80 81
63 }
64 273 $self->{uuid};
65 }
66  
67 ##############################################################################
68  
69  
70 sub entries {
71 830 ▶ my $self = shift;
Subroutine entries: called CC=4 SCAR=13.9
Pod documented
72 830 ▶ my $entries = $self->{entries} //= [];
Condition100%2/2
$self->{"entries"} //= []
l!l
74981
MC/DC100%1/1
$self->{"entries"} //= []
$self->{"entries"}
Truth table100%2/2
A
A= $self->{"entries"}
Aresult
11
00
73 830 ▶ if (@$entries && !blessed($entries->[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$entries and not builtin::blessed($entries->[0])) 12 818 830
Condition100%3/3
@$entries and not builtin::blessed($entries->[0])
!ll&&!rl&&r
59222612
MC/DC100%2/2
@$entries and not builtin::blessed($entries->[0])
@$entries not builtin::blessed($entries->[0])
Truth table100%3/3
A and not(B)
A= @$entriesB= not builtin::blessed($entries->[0])
ABresult
0X0
100
111
74 12 @$entries = map { $self->_wrap_entry($_, $self->kdbx) } @$entries;
75 }
76 830 ▶ assert { !any { !blessed $_ } @$entries };
Subroutine __ANON__: not called CC=1 SCAR=2.6
77 830 return $entries;
78 }
79  
80  
81 sub all_entries {
82 205 ▶ my $self = shift;
Subroutine all_entries: called CC=1 SCAR=0.0
Pod documented
83 205 my %args = @_;
84  
85 205 my $searching = delete $args{searching};
86 205 my $auto_type = delete $args{auto_type};
87 205 my $history = delete $args{history};
88  
89 205 my $groups = $self->all_groups(%args);
90 205 my @entries;
91  
92 return File::KDBX::Iterator->new(sub {
93 335 ▶ if (!@entries) {
Subroutine __ANON__: called CC=10 SCAR=23.0
Branch: 1 branch
BranchTrueFalseTotal
unless (@entries) 282 53 335
94 282 ▶ while (my $group = $groups->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $group = $groups->next) 312 182 494
95 312 ▶ next if $searching && !$group->effective_enable_searching;
Branch: 1 branch
BranchTrueFalseTotal
if $searching and not $group->effective_enable_searching 1 311 312
Condition100%3/3
$searching and not $group->effective_enable_searching
!ll&&!rl&&r
31011
MC/DC50%1/2
$searching and not $group->effective_enable_searching
$searching not $group->effective_enable_searching
Truth table66%2/3
A and not(B)
A= $searchingB= not $group->effective_enable_searching
ABresult
0X0
100
111
96 311 ▶ next if $auto_type && !$group->effective_enable_auto_type;
Branch: 1 branch
BranchTrueFalseTotal
if $auto_type and not $group->effective_enable_auto_type 0 311 311
Condition66%2/3
$auto_type and not $group->effective_enable_auto_type
!ll&&!rl&&r
31010
MC/DC0%0/2
$auto_type and not $group->effective_enable_auto_type
$auto_type not $group->effective_enable_auto_type
Truth table33%1/3
A and not(B)
A= $auto_typeB= not $group->effective_enable_auto_type
ABresult
0X0
100
111
97 311 @entries = @{$group->entries};
98 311 ▶ @entries = grep { $_->auto_type->{enabled} } @entries if $auto_type;
Branch: 1 branch
BranchTrueFalseTotal
if $auto_type 1 310 311
99 311 ▶ @entries = map { ($_, @{$_->history}) } @entries if $history;
Branch: 1 branch
BranchTrueFalseTotal
if $history 220 91 311
100 311 ▶ last if @entries;
Branch: 1 branch
BranchTrueFalseTotal
if @entries 100 211 311
101 }
102 }
103 335 shift @entries;
104 205 });
105 }
106  
107  
108 sub add_entry {
109 29 ▶ my $self = shift;
Subroutine add_entry: called CC=6 SCAR=18.1
Pod documented
110 29 ▶ my $entry = @_ % 2 == 1 ? shift : undef;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 == 1 ? : 5 24 29
111 29 my %args = @_;
112  
113 29 ▶ my $kdbx = delete $args{kdbx} // eval { $self->kdbx };
Condition66%2/3
delete $args{"kdbx"} // eval { do { $self->kdbx } }
l!l&&r!l&&!r
2090
MC/DC0%0/2
delete $args{"kdbx"} // eval { do { $self->kdbx } }
delete $args{"kdbx"} eval { do { $self->kdbx } }
Truth table66%2/3
A // B
A= delete $args{"kdbx"}B= eval { do { $self->kdbx } }
ABresult
1X1
011
000
114  
115 29 ▶ $entry = $self->_wrap_entry($entry // [%args]);
Condition100%2/2
$entry // [%args]
l!l
524
MC/DC100%1/1
$entry // [%args]
$entry
Truth table100%2/2
A
A= $entry
Aresult
11
00
116 29 $entry->uuid;
117 29 ▶ $entry->kdbx($kdbx) if $kdbx;
Branch: 1 branch
BranchTrueFalseTotal
if $kdbx 29 0 29
118  
119 29 ▶ push @{$self->{entries} ||= []}, $entry->remove;
Condition50%1/2
$self->{"entries"} ||= []
l!l
290
MC/DC0%0/1
$self->{"entries"} ||= []
$self->{"entries"}
Truth table50%1/2
A
A= $self->{"entries"}
Aresult
11
00
120 29 return $entry->_set_group($self)->_signal('added', $self);
121 }
122  
123  
124 sub remove_entry {
125 4 ▶ my $self = shift;
Subroutine remove_entry: called CC=6 SCAR=18.1
Pod documented
126 4 ▶ my $uuid = is_ref($_[0]) ? $self->_wrap_entry(shift)->uuid : shift;
Branch: 1 branch
BranchTrueFalseTotal
Ref::Util::XS::is_ref($_[0]) ? : 4 0 4
127 4 my %args = @_;
128 4 my $objects = $self->{entries};
129 4 ▶ for (my $i = 0; $i < @$objects; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$objects) 4 0 4
130 4 my $object = $objects->[$i];
131 4 ▶ next if $uuid ne $object->uuid;
Branch: 1 branch
BranchTrueFalseTotal
if $uuid ne $object->uuid 0 4 4
132 4 $object->_set_group(undef);
133 4 ▶ $object->_signal('removed') if $args{signal} // 1;
Branch: 1 branch
BranchTrueFalseTotal
if $args{"signal"} // 1 3 1 4
Condition100%2/2
$args{"signal"} // 1
l!l
13
MC/DC100%1/1
$args{"signal"} // 1
$args{"signal"}
Truth table100%2/2
A
A= $args{"signal"}
Aresult
11
00
134 4 return splice @$objects, $i, 1;
135 }
136 }
137  
138 ##############################################################################
139  
140  
141 sub groups {
142 1207 ▶ my $self = shift;
Subroutine groups: called CC=4 SCAR=13.9
Pod documented
143 1207 ▶ my $groups = $self->{groups} //= [];
Condition100%2/2
$self->{"groups"} //= []
l!l
112780
MC/DC100%1/1
$self->{"groups"} //= []
$self->{"groups"}
Truth table100%2/2
A
A= $self->{"groups"}
Aresult
11
00
144 1207 ▶ if (@$groups && !blessed($groups->[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$groups and not builtin::blessed($groups->[0])) 7 1200 1207
Condition100%3/3
@$groups and not builtin::blessed($groups->[0])
!ll&&!rl&&r
9192817
MC/DC100%2/2
@$groups and not builtin::blessed($groups->[0])
@$groups not builtin::blessed($groups->[0])
Truth table100%3/3
A and not(B)
A= @$groupsB= not builtin::blessed($groups->[0])
ABresult
0X0
100
111
145 7 @$groups = map { $self->_wrap_group($_, $self->kdbx) } @$groups;
146 }
147 1207 ▶ assert { !any { !blessed $_ } @$groups };
Subroutine __ANON__: not called CC=1 SCAR=2.6
148 1207 return $groups;
149 }
150  
151  
152 sub all_groups {
153 444 ▶ my $self = shift;
Subroutine all_groups: called CC=6 SCAR=17.9
Pod documented
154 444 my %args = @_;
155  
156 444 ▶ my @groups = ($args{inclusive} // 1) ? $self : @{$self->groups};
Branch: 1 branch
BranchTrueFalseTotal
$args{'inclusive'} // 1 ? : 444 0 444
Condition50%1/2
$args{"inclusive"} // 1
l!l
0444
MC/DC0%0/1
$args{"inclusive"} // 1
$args{"inclusive"}
Truth table50%1/2
A
A= $args{"inclusive"}
Aresult
11
00
157 444 ▶ my $algo = lc($args{algorithm} || 'ids');
Condition100%2/2
$args{'algorithm'} || 'ids'
l!l
10434
MC/DC100%1/1
$args{'algorithm'} || 'ids'
$args{'algorithm'}
Truth table100%2/2
A
A= $args{'algorithm'}
Aresult
11
00
158  
159 444 ▶ if ($algo eq ITERATION_DFS) {
Branch: 2 branches
BranchTrueFalseTotal
if ($algo eq 2) { } 4 440 444
elsif ($algo eq 1) { } 3 437 440
160 4 my %visited;
161 return File::KDBX::Iterator->new(sub {
162 21 ▶ my $next = shift @groups or return;
Subroutine __ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
my $next = shift @groups or return 4 17 21
163 17 ▶ if (!$visited{Hash::Util::FieldHash::id($next)}++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($visited{&Hash::Util::FieldHash::id($next)}++) 9 8 17
164 9 ▶ while (my @children = @{$next->groups}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@children) = @{$next->groups;}) 8 9 17
165 8 unshift @groups, @children, $next;
166 8 $next = shift @groups;
167 8 $visited{Hash::Util::FieldHash::id($next)}++;
168 }
169 }
170 17 $next;
171 4 });
172 }
173 elsif ($algo eq ITERATION_BFS) {
174 return File::KDBX::Iterator->new(sub {
175 15 ▶ my $next = shift @groups or return;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
my $next = shift @groups or return 3 12 15
176 12 push @groups, @{$next->groups};
177 12 $next;
178 3 });
179 }
180 return File::KDBX::Iterator->new(sub {
181 1025 ▶ my $next = shift @groups or return;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
my $next = shift @groups or return 393 632 1025
182 632 unshift @groups, @{$next->groups};
183 632 $next;
184 437 });
185 }
186  
187 0 ▶sub _kpx_groups { shift->groups(@_) }
Subroutine _kpx_groups: not called CC=1 SCAR=6.9
188  
189  
190 sub add_group {
191 19 ▶ my $self = shift;
Subroutine add_group: called CC=6 SCAR=18.1
Pod documented
192 19 ▶ my $group = @_ % 2 == 1 ? shift : undef;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 == 1 ? : 1 18 19
193 19 my %args = @_;
194  
195 19 ▶ my $kdbx = delete $args{kdbx} // eval { $self->kdbx };
Condition66%2/3
delete $args{"kdbx"} // eval { do { $self->kdbx } }
l!l&&r!l&&!r
1540
MC/DC0%0/2
delete $args{"kdbx"} // eval { do { $self->kdbx } }
delete $args{"kdbx"} eval { do { $self->kdbx } }
Truth table66%2/3
A // B
A= delete $args{"kdbx"}B= eval { do { $self->kdbx } }
ABresult
1X1
011
000
196  
197 19 ▶ $group = $self->_wrap_group($group // [%args]);
Condition100%2/2
$group // [%args]
l!l
118
MC/DC100%1/1
$group // [%args]
$group
Truth table100%2/2
A
A= $group
Aresult
11
00
198 19 $group->uuid;
199 19 ▶ $group->kdbx($kdbx) if $kdbx;
Branch: 1 branch
BranchTrueFalseTotal
if $kdbx 19 0 19
200  
201 19 ▶ push @{$self->{groups} ||= []}, $group->remove;
Condition50%1/2
$self->{"groups"} ||= []
l!l
190
MC/DC0%0/1
$self->{"groups"} ||= []
$self->{"groups"}
Truth table50%1/2
A
A= $self->{"groups"}
Aresult
11
00
202 19 return $group->_set_group($self)->_signal('added', $self);
203 }
204  
205  
206 sub remove_group {
207 3 ▶ my $self = shift;
Subroutine remove_group: called CC=6 SCAR=18.8
Pod documented
208 3 ▶ my $uuid = is_ref($_[0]) ? $self->_wrap_group(shift)->uuid : shift;
Branch: 1 branch
BranchTrueFalseTotal
Ref::Util::XS::is_ref($_[0]) ? : 3 0 3
209 3 my %args = @_;
210 3 my $objects = $self->{groups};
211 3 ▶ for (my $i = 0; $i < @$objects; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$objects) 3 0 3
212 3 my $object = $objects->[$i];
213 3 ▶ next if $uuid ne $object->uuid;
Branch: 1 branch
BranchTrueFalseTotal
if $uuid ne $object->uuid 0 3 3
214 3 $object->_set_group(undef);
215 3 ▶ $object->_signal('removed') if $args{signal} // 1;
Branch: 1 branch
BranchTrueFalseTotal
if $args{"signal"} // 1 3 0 3
Condition50%1/2
$args{"signal"} // 1
l!l
03
MC/DC0%0/1
$args{"signal"} // 1
$args{"signal"}
Truth table50%1/2
A
A= $args{"signal"}
Aresult
11
00
216 3 return splice @$objects, $i, 1;
217 }
218 }
219  
220 ##############################################################################
221  
222  
223 sub all_objects {
224 106 ▶ my $self = shift;
Subroutine all_objects: called CC=1 SCAR=0.1
Pod documented
225 106 my %args = @_;
226  
227 106 my $searching = delete $args{searching};
228 106 my $auto_type = delete $args{auto_type};
229 106 my $history = delete $args{history};
230  
231 106 my $groups = $self->all_groups(%args);
232 106 my @entries;
233  
234 return File::KDBX::Iterator->new(sub {
235 284 ▶ if (!@entries) {
Subroutine __ANON__: called CC=9 SCAR=23.4
Branch: 1 branch
BranchTrueFalseTotal
unless (@entries) 247 37 284
236 247 ▶ while (my $group = $groups->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $group = $groups->next) 152 95 247
237 152 ▶ next if $searching && !$group->effective_enable_searching;
Branch: 1 branch
BranchTrueFalseTotal
if $searching and not $group->effective_enable_searching 0 152 152
Condition33%1/3
$searching and not $group->effective_enable_searching
!ll&&!rl&&r
15200
MC/DC0%0/2
$searching and not $group->effective_enable_searching
$searching not $group->effective_enable_searching
Truth table33%1/3
A and not(B)
A= $searchingB= not $group->effective_enable_searching
ABresult
0X0
100
111
238 152 ▶ next if $auto_type && !$group->effective_enable_auto_type;
Branch: 1 branch
BranchTrueFalseTotal
if $auto_type and not $group->effective_enable_auto_type 0 152 152
Condition33%1/3
$auto_type and not $group->effective_enable_auto_type
!ll&&!rl&&r
15200
MC/DC0%0/2
$auto_type and not $group->effective_enable_auto_type
$auto_type not $group->effective_enable_auto_type
Truth table33%1/3
A and not(B)
A= $auto_typeB= not $group->effective_enable_auto_type
ABresult
0X0
100
111
239 152 @entries = @{$group->entries};
240 152 ▶ @entries = grep { $_->auto_type->{enabled} } @entries if $auto_type;
Branch: 1 branch
BranchTrueFalseTotal
if $auto_type 0 152 152
241 152 ▶ @entries = map { ($_, @{$_->history}) } @entries if $history;
Branch: 1 branch
BranchTrueFalseTotal
if $history 2 150 152
242 152 return $group;
243 }
244 }
245 132 shift @entries;
246 106 });
247 }
248  
249  
250 sub add_object {
251 4 ▶ my $self = shift;
Subroutine add_object: called CC=3 SCAR=11.0
Pod documented
252 4 my $obj = shift;
253 4 ▶ if ($obj->isa('File::KDBX::Entry')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($obj->isa('File::KDBX::Entry')) { } 3 1 4
elsif ($obj->isa('File::KDBX::Group')) { } 1 0 1
254 3 $self->add_entry($obj);
255 }
256 elsif ($obj->isa('File::KDBX::Group')) {
257 1 $self->add_group($obj);
258 }
259 }
260  
261  
262 sub remove_object {
263 7 ▶ my $self = shift;
Subroutine remove_object: called CC=6 SCAR=21.6
Pod documented
264 7 my $object = shift;
265 7 my $blessed = blessed($object);
266 7 ▶ return $self->remove_group($object, @_) if $blessed && $object->isa('File::KDBX::Group');
Branch: 1 branch
BranchTrueFalseTotal
if $blessed and $object->isa("File::KDBX::Group") 3 4 7
Condition66%2/3
$blessed and $object->isa("File::KDBX::Group")
!ll&&!rl&&r
043
MC/DC50%1/2
$blessed and $object->isa("File::KDBX::Group")
$blessed $object->isa("File::KDBX::Group")
Truth table66%2/3
A and B
A= $blessedB= $object->isa("File::KDBX::Group")
ABresult
0X0
100
111
267 4 ▶ return $self->remove_entry($object, @_) if $blessed && $object->isa('File::KDBX::Entry');
Branch: 1 branch
BranchTrueFalseTotal
if $blessed and $object->isa("File::KDBX::Entry") 4 0 4
Condition33%1/3
$blessed and $object->isa("File::KDBX::Entry")
!ll&&!rl&&r
004
MC/DC0%0/2
$blessed and $object->isa("File::KDBX::Entry")
$blessed $object->isa("File::KDBX::Entry")
Truth table33%1/3
A and B
A= $blessedB= $object->isa("File::KDBX::Entry")
ABresult
0X0
100
111
268 0 ▶ return $self->remove_group($object, @_) || $self->remove_entry($object, @_);
Condition0%0/3
$self->remove_group($object, @_) || $self->remove_entry($object, @_)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->remove_group($object, @_) || $self->remove_entry($object, @_)
$self->remove_group($object, @_) $self->remove_entry($object, @_)
Truth table0%0/3
A || B
A= $self->remove_group($object, @_)B= $self->remove_entry($object, @_)
ABresult
1X1
011
000
269 }
270  
271 ##############################################################################
272  
273  
274 sub effective_default_auto_type_sequence {
275 0 ▶ my $self = shift;
Subroutine effective_default_auto_type_sequence: not called CC=3 SCAR=24.8
Pod documented
276 0 my $sequence = $self->default_auto_type_sequence;
277 0 ▶ return $sequence if defined $sequence;
Branch: 1 branch
BranchTrueFalseTotal
if defined $sequence 0 0 0
278  
279 0 ▶ my $parent = $self->group or return '{USERNAME}{TAB}{PASSWORD}{ENTER}';
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $self->group or return "{USERNAME}{TAB}{PASSWORD}{ENTER}" 0 0 0
280 0 return $parent->effective_default_auto_type_sequence;
281 }
282  
283  
284 sub effective_enable_auto_type {
285 1 ▶ my $self = shift;
Subroutine effective_enable_auto_type: called CC=3 SCAR=12.0
Pod documented
286 1 my $enabled = $self->enable_auto_type;
287 1 ▶ return $enabled if defined $enabled;
Branch: 1 branch
BranchTrueFalseTotal
if defined $enabled 0 1 1
288  
289 1 ▶ my $parent = $self->group or return true;
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $self->group or return &true() 1 0 1
290 0 return $parent->effective_enable_auto_type;
291 }
292  
293  
294 sub effective_enable_searching {
295 2 ▶ my $self = shift;
Subroutine effective_enable_searching: called CC=3 SCAR=11.3
Pod documented
296 2 my $enabled = $self->enable_searching;
297 2 ▶ return $enabled if defined $enabled;
Branch: 1 branch
BranchTrueFalseTotal
if defined $enabled 1 1 2
298  
299 1 ▶ my $parent = $self->group or return true;
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $self->group or return &true() 1 0 1
300 0 return $parent->effective_enable_searching;
301 }
302  
303 ##############################################################################
304  
305  
306 sub is_empty {
307 5 ▶ my $self = shift;
Subroutine is_empty: called CC=2 SCAR=6.9
Pod documented
308 5 ▶ return @{$self->groups} == 0 && @{$self->entries} == 0;
Condition100%3/3
@{$self->groups;} == 0 && @{$self->entries;} == 0
!ll&&!rl&&r
113
MC/DC100%2/2
@{$self->groups;} == 0 && @{$self->entries;} == 0
@{$self->groups;} == 0 @{$self->entries;} == 0
Truth table100%3/3
A && B
A= @{$self->groups;} == 0B= @{$self->entries;} == 0
ABresult
0X0
100
111
309 }
310  
311  
312 sub is_root {
313 8 ▶ my $self = shift;
Subroutine is_root: called CC=2 SCAR=7.0
Pod documented
314 8 ▶ my $kdbx = eval { $self->kdbx } or return FALSE;
Branch: 1 branch
BranchTrueFalseTotal
my $kdbx = eval { do { $self->kdbx } } or return !!0 0 8 8
315 8 return Hash::Util::FieldHash::id($kdbx->root) == Hash::Util::FieldHash::id($self);
316 }
317  
318  
319 sub is_recycle_bin {
320 5 ▶ my $self = shift;
Subroutine is_recycle_bin: called CC=3 SCAR=11.2
Pod documented
321 5 ▶ my $kdbx = eval { $self->kdbx } or return FALSE;
Branch: 1 branch
BranchTrueFalseTotal
my $kdbx = eval { do { $self->kdbx } } or return !!0 0 5 5
322 5 my $group = $kdbx->recycle_bin;
323 5 ▶ return $group && Hash::Util::FieldHash::id($group) == Hash::Util::FieldHash::id($self);
Condition66%2/3
$group && &Hash::Util::FieldHash::id($group) == &Hash::Util::FieldHash::id($self)
!ll&&!rl&&r
032
MC/DC50%1/2
$group && &Hash::Util::FieldHash::id($group) == &Hash::Util::FieldHash::id($self)
$group &Hash::Util::FieldHash::id($group) == &Hash::Util::FieldHash::id($self)
Truth table66%2/3
A && B
A= $groupB= &Hash::Util::FieldHash::id($group) == &Hash::Util::FieldHash::id($self)
ABresult
0X0
100
111
324 }
325  
326  
327 sub is_entry_templates {
328 0 ▶ my $self = shift;
Subroutine is_entry_templates: not called CC=3 SCAR=24.8
Pod documented
329 0 ▶ my $kdbx = eval { $self->kdbx } or return FALSE;
Branch: 1 branch
BranchTrueFalseTotal
my $kdbx = eval { do { $self->kdbx } } or return !!0 0 0 0
330 0 my $group = $kdbx->entry_templates;
331 0 ▶ return $group && Hash::Util::FieldHash::id($group) == Hash::Util::FieldHash::id($self);
Condition0%0/3
$group && &Hash::Util::FieldHash::id($group) == &Hash::Util::FieldHash::id($self)
!ll&&!rl&&r
000
MC/DC0%0/2
$group && &Hash::Util::FieldHash::id($group) == &Hash::Util::FieldHash::id($self)
$group &Hash::Util::FieldHash::id($group) == &Hash::Util::FieldHash::id($self)
Truth table0%0/3
A && B
A= $groupB= &Hash::Util::FieldHash::id($group) == &Hash::Util::FieldHash::id($self)
ABresult
0X0
100
111
332 }
333  
334  
335 sub is_last_selected {
336 0 ▶ my $self = shift;
Subroutine is_last_selected: not called CC=3 SCAR=24.8
Pod documented
337 0 ▶ my $kdbx = eval { $self->kdbx } or return FALSE;
Branch: 1 branch
BranchTrueFalseTotal
my $kdbx = eval { do { $self->kdbx } } or return !!0 0 0 0
338 0 my $group = $kdbx->last_selected;
339 0 ▶ return $group && Hash::Util::FieldHash::id($group) == Hash::Util::FieldHash::id($self);
Condition0%0/3
$group && &Hash::Util::FieldHash::id($group) == &Hash::Util::FieldHash::id($self)
!ll&&!rl&&r
000
MC/DC0%0/2
$group && &Hash::Util::FieldHash::id($group) == &Hash::Util::FieldHash::id($self)
$group &Hash::Util::FieldHash::id($group) == &Hash::Util::FieldHash::id($self)
Truth table0%0/3
A && B
A= $groupB= &Hash::Util::FieldHash::id($group) == &Hash::Util::FieldHash::id($self)
ABresult
0X0
100
111
340 }
341  
342  
343 sub is_last_top_visible {
344 0 ▶ my $self = shift;
Subroutine is_last_top_visible: not called CC=3 SCAR=24.8
Pod documented
345 0 ▶ my $kdbx = eval { $self->kdbx } or return FALSE;
Branch: 1 branch
BranchTrueFalseTotal
my $kdbx = eval { do { $self->kdbx } } or return !!0 0 0 0
346 0 my $group = $kdbx->last_top_visible;
347 0 ▶ return $group && Hash::Util::FieldHash::id($group) == Hash::Util::FieldHash::id($self);
Condition0%0/3
$group && &Hash::Util::FieldHash::id($group) == &Hash::Util::FieldHash::id($self)
!ll&&!rl&&r
000
MC/DC0%0/2
$group && &Hash::Util::FieldHash::id($group) == &Hash::Util::FieldHash::id($self)
$group &Hash::Util::FieldHash::id($group) == &Hash::Util::FieldHash::id($self)
Truth table0%0/3
A && B
A= $groupB= &Hash::Util::FieldHash::id($group) == &Hash::Util::FieldHash::id($self)
ABresult
0X0
100
111
348 }
349  
350  
351 sub path {
352 3 ▶ my $self = shift;
Subroutine path: called CC=3 SCAR=11.0
Pod documented
353 3 ▶ return $self->name if $self->is_root;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_root 1 2 3
354 2 ▶ my $lineage = $self->lineage or return;
Branch: 1 branch
BranchTrueFalseTotal
my $lineage = $self->lineage or return 0 2 2
355 2 my @parts = (@$lineage, $self);
356 2 shift @parts;
357 2 return join('.', map { $_->name } @parts);
358 }
359  
360  
361 sub size {
362 0 ▶ my $self = shift;
Subroutine size: not called CC=1 SCAR=6.9
Pod documented
363 0 return sum0 map { $_->size } @{$self->groups}, @{$self->entries};
364 }
365  
366  
367 0 ▶sub depth { $_[0]->is_root ? 0 : (scalar @{$_[0]->lineage || []} || -1) }
Subroutine depth: not called CC=4 SCAR=30.0
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
$_[0]->is_root ? : 0 0 0
$_[0]->lineage or [] 0 0 0
Condition0%0/2
scalar @{$_[0]->lineage or [];} or -1
l!l
00
MC/DC0%0/1
scalar @{$_[0]->lineage or [];} or -1
scalar @{$_[0]->lineage or [];}
Truth table0%0/2
A
A= scalar @{$_[0]->lineage or [];}
Aresult
11
00
368  
369 sub _signal {
370 23 ▶ my $self = shift;
Subroutine _signal: called CC=1 SCAR=0.0
371 23 my $type = shift;
372 23 return $self->SUPER::_signal("group.$type", @_);
373 }
374  
375 sub _commit {
376 6 ▶ my $self = shift;
Subroutine _commit: called CC=1 SCAR=0.0
377 6 my $time = gmtime;
378 6 $self->last_modification_time($time);
379 6 $self->last_access_time($time);
380 }
381  
382 65 ▶sub label { shift->name(@_) }
Subroutine label: called CC=1 SCAR=0.0
Pod documented
383  
384 ### Name of the parent attribute expected to contain the object
385 9 ▶sub _parent_container { 'groups' }
Subroutine _parent_container: called CC=1 SCAR=0.0
386  
387 10 1;
388  
389 __END__
« KDBX/IO/Crypt.pm ↑ Summary KDBX/Cipher/Stream.pm »