File Coverage

lib/File/Information/Filesystem.pm
Criterion Covered Total %
statement 14 35 40.0
branch 0 18 0.0
condition 0 11 0.0
subroutine 5 7 71.4
pod n/a
total 19 71 26.7


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::Filesystem;
9              
10 3     3   48 use v5.10;
  3         13  
11 3     3   17 use strict;
  3         5  
  3         105  
12 3     3   15 use warnings;
  3         34  
  3         263  
13              
14 3     3   39 use parent 'File::Information::Base';
  3         5  
  3         28  
15              
16 3     3   247 use Carp;
  3         6  
  3         1805  
17              
18             our $VERSION = v0.16;
19              
20             my @_copy_properties = (
21             qw(dos_device dos_path),
22             qw(mountpoint fs_type),
23             qw(linux_mount_options linux_superblock_options),
24             );
25              
26             my %_properties = (
27             dev_disk_by_uuid => {rawtype => 'uuid'},
28             dev_disk_by_label => {},
29             dev_name => {},
30             dev_mapper_name => {},
31             (map {$_ => {}}
32             @_copy_properties,
33             ),
34             );
35              
36             my %_known_paths = (
37             '/dev/disk/by-uuid' => 'uuid',
38             '/dev/disk/by-label' => 'label',
39             '/dev/mapper' => 'mapper',
40             '/dev' => 'dev',
41             );
42              
43             sub _new {
44 0     0     my ($pkg, %opts) = @_;
45 0           my $self = $pkg->SUPER::_new(%opts, properties => \%_properties);
46 0   0       my $pv = ($self->{properties_values} //= {})->{current} //= {};
      0        
47              
48 0 0 0       croak 'No stat or dirstat is given' unless defined($self->{stat}) || defined($self->{dirstat});
49 0 0         croak 'No paths is given' unless defined $self->{paths};
50              
51 0           foreach my $key (keys %{$self->{paths}}) {
  0            
52 0 0         my $known = $_known_paths{$key} or next;
53 0           foreach my $value (@{$self->{paths}{$key}}) {
  0            
54 0 0         if ($known eq 'uuid') {
    0          
    0          
    0          
55 0 0         if ($value =~ __PACKAGE__->SUPER::RE_UUID) {
56 0           $pv->{dev_disk_by_uuid} = {raw => $value};
57             }
58             } elsif ($known eq 'label') {
59 0           $pv->{dev_disk_by_label} = {raw => $value};
60             } elsif ($known eq 'dev') {
61 0   0       $pv->{dev_name} //= {raw => $value};
62             } elsif ($known eq 'mapper') {
63 0   0       $pv->{dev_mapper_name} //= {raw => $value};
64             }
65             }
66             }
67              
68             # Simple keys:
69 0           foreach my $key (@_copy_properties) {
70 0 0         if (defined $self->{$key}) {
71 0           $pv->{$key} = {raw => $self->{$key}};
72             }
73             }
74              
75 0           return $self;
76             }
77              
78             # ----------------
79              
80             sub _default_device_search_paths {
81 0     0     return state $defaults = [qw(/dev /dev/disk/by-id /dev/mapper), keys %_known_paths];
82             }
83              
84             1;
85              
86             __END__
87              
88             =pod
89              
90             =encoding UTF-8
91              
92             =head1 NAME
93              
94             File::Information::Filesystem - generic module for extracting information from filesystems
95              
96             =head1 VERSION
97              
98             version v0.16
99              
100             =head1 SYNOPSIS
101              
102             use File::Information;
103              
104             my File::Information::Filesystem $filesystem = $instance->for_link($path)->filesystem;
105              
106             my File::Information::Filesystem $filesystem = $instance->for_handle($path)->filesystem;
107              
108             B<Note:> This package inherits from L<File::Information::Base>.
109              
110             This module represents a filesystem. A filesystem is the the stroage structure for inodes, hardlinks and maybe other types of objects.
111              
112             =head1 METHODS
113              
114             =head1 AUTHOR
115              
116             Philipp Schafft <lion@cpan.org>
117              
118             =head1 COPYRIGHT AND LICENSE
119              
120             This software is Copyright (c) 2024-2025 by Philipp Schafft <lion@cpan.org>.
121              
122             This is free software, licensed under:
123              
124             The Artistic License 2.0 (GPL Compatible)
125              
126             =cut