File Coverage

lib/File/Information/Remote.pm
Criterion Covered Total %
statement 14 52 26.9
branch 0 8 0.0
condition 0 18 0.0
subroutine 5 8 62.5
pod n/a
total 19 86 22.0


line stmt bran cond sub pod time code
1             # Copyright (c) 2024-2025 Philipp Schafft <lion@cpan.org>
2              
3             # licensed under Artistic License 2.0 (see LICENSE file)
4              
5             # ABSTRACT: generic module for extracting information from filesystems
6              
7              
8             package File::Information::Remote;
9              
10 1     1   4535 use v5.10;
  1         3  
11 1     1   4 use strict;
  1         2  
  1         37  
12 1     1   5 use warnings;
  1         1  
  1         57  
13              
14 1     1   5 use parent 'File::Information::Base';
  1         2  
  1         10  
15              
16 1     1   110 use Carp;
  1         1  
  1         3253  
17              
18             our $VERSION = v0.16;
19              
20             my %_properties = (
21             data_uriid_attr_displayname => {loader => \&_load_data_uriid},
22             data_uriid_attr_media_subtype => {loader => \&_load_data_uriid, rawtype => 'mediatype'},
23             data_uriid_attr_thumbnail => {loader => \&_load_data_uriid},
24             data_uriid_id => {loader => \&_load_data_uriid},
25             data_uriid_ise => {loader => \&_load_data_uriid, rawtype => 'ise'},
26             data_uriid_type => {loader => \&_load_data_uriid, rawtype => 'ise'},
27             data_uriid_result => {loader => \&_load_data_uriid, rawtype => 'Data::URIID::Result'},
28             store_file => {loader => \&_load_fstore, rawtype => 'File::FStore::File'},
29             );
30              
31             # ----------------
32              
33             sub _new {
34 0     0     my ($pkg, %opts) = @_;
35 0           my $self = $pkg->SUPER::_new(%opts, properties => \%_properties);
36              
37 0           return $self;
38             }
39              
40             sub _load_data_uriid {
41 0     0     my ($self) = @_;
42 0   0       my $result = $self->{data_uriid_result} // return;
43 0   0       my $pv = ($self->{properties_values} //= {})->{current} //= {};
      0        
44              
45 0 0         return if $self->{_loaded_data_uriid};
46 0           $self->{_loaded_data_uriid} = 1;
47              
48 0           eval {$pv->{data_uriid_ise} = {raw => $result->ise}};
  0            
49 0           eval {$pv->{data_uriid_id} = {raw => $result->id}};
  0            
50 0           eval {$pv->{data_uriid_type} = {raw => $result->id_type(as => 'ise')}};
  0            
51 0           $pv->{data_uriid_result} = {raw => $result};
52              
53 0           foreach my $digest ($result->available_keys('digest')) {
54 0   0       my $value = $result->digest($digest, as => 'hex', default => undef) // next;
55 0           $self->{digest}{current}{$digest} = $value;
56             }
57              
58 0           foreach my $key (grep {/^data_uriid_attr_/} keys %_properties) {
  0            
59 0           my $real_key = $key =~ s/^data_uriid_attr_//r;
60 0   0       my $value = $result->attribute($real_key, as => 'string', default => undef) // next;
61 0           $pv->{$key} = {raw => $value};
62             }
63             }
64              
65             sub _load_fstore {
66 0     0     my ($self, $key, %opts) = @_;
67 0           my $ise;
68             my @candidates;
69              
70 0 0         return if $self->{_loaded_fstore};
71 0           $self->{_loaded_fstore} = 1;
72              
73 0           $ise = $self->get('data_uriid_ise', default => undef);
74              
75 0 0         return unless defined $ise;;
76              
77 0           foreach my $store ($self->instance->store(as => 'File::FStore')) {
78 0           push(@candidates, $store->query(ise => $ise));
79             }
80              
81 0 0         if (scalar(@candidates)) {
82 0   0       my $pv_current = ($self->{properties_values} //= {})->{current} //= {};
      0        
83 0   0       my $pv_final = ($self->{properties_values} //= {})->{final} //= {};
      0        
84              
85 0           $pv_current->{store_file} = [map {{raw => $_}} @candidates];
  0            
86 0           $pv_final->{store_file} = [map {{raw => $_}} @candidates];
  0            
87             }
88             }
89              
90             1;
91              
92             __END__
93              
94             =pod
95              
96             =encoding UTF-8
97              
98             =head1 NAME
99              
100             File::Information::Remote - generic module for extracting information from filesystems
101              
102             =head1 VERSION
103              
104             version v0.16
105              
106             =head1 SYNOPSIS
107              
108             use File::Information;
109              
110             my File::Information $instance = File::Information->new(%config);
111              
112             my File::Information::Remote $link = $instance->for_...(...);
113              
114             B<Note:> This package inherits from L<File::Information::Base>.
115              
116             This package represents a remote object (such as a remote hardlink or inode).
117              
118             =head1 METHODS
119              
120             =head1 AUTHOR
121              
122             Philipp Schafft <lion@cpan.org>
123              
124             =head1 COPYRIGHT AND LICENSE
125              
126             This software is Copyright (c) 2024-2025 by Philipp Schafft <lion@cpan.org>.
127              
128             This is free software, licensed under:
129              
130             The Artistic License 2.0 (GPL Compatible)
131              
132             =cut