| 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 | use v5.10; | ||
| 11 | use strict; | ||
| 12 | use warnings; | ||
| 13 | |||
| 14 | use parent 'File::Information::Base'; | ||
| 15 | |||
| 16 | use Carp; | ||
| 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 | my ($pkg, %opts) = @_; | ||
| 35 | my $self = $pkg->SUPER::_new(%opts, properties => \%_properties); | ||
| 36 | |||
| 37 | return $self; | ||
| 38 | } | ||
| 39 | |||
| 40 | sub _load_data_uriid { | ||
| 41 | my ($self) = @_; | ||
| 42 | my $result = $self->{data_uriid_result} // return; | ||
| 43 | my $pv = ($self->{properties_values} //= {})->{current} //= {}; | ||
| 44 | |||
| 45 | return if $self->{_loaded_data_uriid}; | ||
| 46 | $self->{_loaded_data_uriid} = 1; | ||
| 47 | |||
| 48 | eval {$pv->{data_uriid_ise} = {raw => $result->ise}}; | ||
| 49 | eval {$pv->{data_uriid_id} = {raw => $result->id}}; | ||
| 50 | eval {$pv->{data_uriid_type} = {raw => $result->id_type(as => 'ise')}}; | ||
| 51 | $pv->{data_uriid_result} = {raw => $result}; | ||
| 52 | |||
| 53 | foreach my $digest ($result->available_keys('digest')) { | ||
| 54 | my $value = $result->digest($digest, as => 'hex', default => undef) // next; | ||
| 55 | $self->{digest}{current}{$digest} = $value; | ||
| 56 | } | ||
| 57 | |||
| 58 | foreach my $key (grep {/^data_uriid_attr_/} keys %_properties) { | ||
| 59 | my $real_key = $key =~ s/^data_uriid_attr_//r; | ||
| 60 | my $value = $result->attribute($real_key, as => 'string', default => undef) // next; | ||
| 61 | $pv->{$key} = {raw => $value}; | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | sub _load_fstore { | ||
| 66 | my ($self, $key, %opts) = @_; | ||
| 67 | my $ise; | ||
| 68 | my @candidates; | ||
| 69 | |||
| 70 | return if $self->{_loaded_fstore}; | ||
| 71 | $self->{_loaded_fstore} = 1; | ||
| 72 | |||
| 73 | $ise = $self->get('data_uriid_ise', default => undef); | ||
| 74 | |||
| 75 | return unless defined $ise;; | ||
| 76 | |||
| 77 | foreach my $store ($self->instance->store(as => 'File::FStore')) { | ||
| 78 | push(@candidates, $store->query(ise => $ise)); | ||
| 79 | } | ||
| 80 | |||
| 81 | if (scalar(@candidates)) { | ||
| 82 | my $pv_current = ($self->{properties_values} //= {})->{current} //= {}; | ||
| 83 | my $pv_final = ($self->{properties_values} //= {})->{final} //= {}; | ||
| 84 | |||
| 85 | $pv_current->{store_file} = [map {{raw => $_}} @candidates]; | ||
| 86 | $pv_final->{store_file} = [map {{raw => $_}} @candidates]; | ||
| 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 |