line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
5
|
|
|
5
|
|
5091
|
use 5.006; |
|
5
|
|
|
|
|
10
|
|
2
|
5
|
|
|
5
|
|
14
|
use strict; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
70
|
|
3
|
5
|
|
|
5
|
|
12
|
use warnings; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
188
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Metabase::Fact::Hash; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.025'; |
8
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
14
|
use Carp (); |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
51
|
|
10
|
5
|
|
|
5
|
|
11
|
use JSON::MaybeXS (); |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
54
|
|
11
|
|
|
|
|
|
|
|
12
|
5
|
|
|
5
|
|
12
|
use Metabase::Fact; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
1271
|
|
13
|
|
|
|
|
|
|
our @ISA = qw/Metabase::Fact/; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub validate_content { |
16
|
7
|
|
|
7
|
1
|
6
|
my ($self) = @_; |
17
|
7
|
|
|
|
|
13
|
my $content = $self->content; |
18
|
7
|
|
|
|
|
7
|
my $class = ref $self; |
19
|
7
|
50
|
|
|
|
13
|
Carp::confess "content must be a hashref" |
20
|
|
|
|
|
|
|
unless ref $content eq 'HASH'; |
21
|
7
|
|
50
|
0
|
|
17
|
my $get_req = $self->can('required_keys') || sub { () }; |
|
0
|
|
|
|
|
0
|
|
22
|
7
|
|
50
|
0
|
|
23
|
my $get_opt = $self->can('optional_keys') || sub { () }; |
|
0
|
|
|
|
|
0
|
|
23
|
|
|
|
|
|
|
# find missing |
24
|
7
|
|
|
|
|
10
|
my @missing = grep { !exists $content->{$_} } $get_req->(); |
|
7
|
|
|
|
|
28
|
|
25
|
7
|
100
|
|
|
|
183
|
Carp::croak "missing required keys for $class\: @missing\n" if @missing; |
26
|
|
|
|
|
|
|
# check for invalid |
27
|
6
|
|
|
|
|
7
|
my %valid = map { $_ => 1 } ( $get_req->(), $get_opt->() ); |
|
12
|
|
|
|
|
30
|
|
28
|
6
|
|
|
|
|
11
|
my @invalid = grep { !exists $valid{$_} } keys %$content; |
|
10
|
|
|
|
|
13
|
|
29
|
6
|
100
|
|
|
|
118
|
Carp::croak "invalid keys for $class\: @invalid\n" if @invalid; |
30
|
5
|
|
|
|
|
11
|
return 1; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub content_as_bytes { |
34
|
5
|
|
|
5
|
1
|
5
|
my ($self) = @_; |
35
|
5
|
|
|
|
|
18
|
return JSON::MaybeXS->new(ascii => 1)->encode( $self->content ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub content_from_bytes { |
39
|
1
|
|
|
1
|
1
|
1
|
my ( $class, $bytes ) = @_; |
40
|
1
|
|
|
|
|
4
|
return JSON::MaybeXS->new(ascii => 1)->decode($bytes); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# ABSTRACT: fact subtype for simple hashes |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |