blib/lib/Archive/Libarchive/Entry.pm

filter: Statementstmt 100% 17 / 17 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 100% 23 / 23 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Archive/Libarchive/DiskWrite.pm ↑ Summary blib/lib/Archive/Libarchive/EntryLinkResolver.pm »
1 package Archive::Libarchive::Entry;
2  
3 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 17 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 17 ▶use Archive::Libarchive::Lib;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 17 ▶use FFI::Platypus::Buffer qw( buffer_to_scalar scalar_to_buffer );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 17 ▶use experimental qw( signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # ABSTRACT: Libarchive entry class
11 our $VERSION = '0.10'; # VERSION
12  
13 my $ffi = Archive::Libarchive::Lib->ffi;
14  
15  
16 $ffi->mangler(sub ($name) { "archive_entry_$name" });
17  
18 $ffi->attach( new => [] => 'opaque' => sub {
19 my($xsub, $class) = @_;
20 my $ptr = $xsub->();
21 bless { ptr => $ptr }, $class;
22 });
23  
24  
25 # TODO: these constants can't currently be extracted by
26 # Const::Introspect::C. Though to be fair these are unlikely
27 # to need changing.
28 # NOTE: the header file has some logic to use ushort instead of
29 # mode_t on Windows, but on Strawberry at least, mode_t is
30 # already a ushort. This will likely be switched to a uint
31 # in 4.x
32 $ffi->load_custom_type( '::Enum', 'archive_entry_filetype_ret_t',
33 { prefix => 'AE_IF', rev => 'dualvar', type => 'mode_t', package => 'Archive::Libarchive' },
34 [ mt => oct('170000') ],
35 [ reg => oct('100000') ],
36 [ lnk => oct('120000') ],
37 [ sock => oct('140000') ],
38 [ chr => oct('020000') ],
39 [ blk => oct('060000') ],
40 [ dir => oct('040000') ],
41 [ ifo => oct('010000') ],
42 );
43  
44 $ffi->load_custom_type( '::Enum', 'archive_entry_filetype_t',
45 { prefix => 'AE_IF', type => 'uint', package => 'Archive::Libarchive' },
46 [ mt => oct('170000') ],
47 [ reg => oct('100000') ],
48 [ lnk => oct('120000') ],
49 [ sock => oct('140000') ],
50 [ chr => oct('020000') ],
51 [ blk => oct('060000') ],
52 [ dir => oct('040000') ],
53 [ ifo => oct('010000') ],
54 );
55  
56 $ffi->attach( filetype => ['archive_entry'] => 'archive_entry_filetype_ret_t' );
57 $ffi->attach( set_filetype => ['archive_entry', 'archive_entry_filetype_t'] );
58  
59 $ffi->attach( xattr_add_entry => ['archive_entry', 'string', 'opaque', 'size_t'] => sub {
60 my $xsub = shift;
61 my($ptr, $size) = scalar_to_buffer($_[2]);
62 $xsub->($_[0], $_[1], $ptr, $size);
63 });
64  
65 $ffi->attach( xattr_next => ['archive_entry', 'string*', 'opaque*', 'size_t*'] => 'int' => sub {
66 my($xsub, $self, $ref_name, $ref_value) = @_;
67 my($ptr, $size);
68 my $ret = $xsub->($self, $ref_name, \$ptr, \$size);
69 if(defined $ptr)
70 { $$ref_value = buffer_to_scalar($ptr, $size) }
71 else
72 { $$ref_value = undef }
73 return $ret;
74 });
75  
76 if($^O ne 'MSWin32')
77 {
78 require FFI::C::Stat;
79 $ffi->attach( copy_stat => ['archive_entry', 'stat'] );
80 $ffi->attach( stat => ['archive_entry'] => opaque => sub {
81 my($xsub, $self) = @_;
82 my $ptr = $xsub->($self);
83 defined $ptr ? FFI::C::Stat->clone($ptr) : undef;
84 });
85 }
86 else
87 {
88 # https://github.com/uperl/Archive-Libarchive/issues/19
89 require Carp;
90 *copy_stat = sub { Carp::croak("Not implemented on this platform") };
91 *stat = sub { Carp::croak("Not implemented on this platform") };
92 }
93  
94 $ffi->attach( clone => ['archive_entry'] => 'archive_entry' );
95  
96 $ffi->attach( copy_mac_metadata => ['archive_entry', 'opaque', 'size_t'] => sub {
97 my $xsub = shift;
98 my $self = shift;
99 my($ptr, $size) = scalar_to_buffer $_[0];
100 $xsub->($self, $ptr, $size);
101 });
102  
103  
104 $ffi->attach( mac_metadata => ['archive_entry', 'size_t*'] => 'opaque' => sub {
105 my($xsub, $self) = @_;
106 my $size;
107 my $ptr = $xsub->($self, \$size);
108 defined $ptr ? buffer_to_scalar($ptr, $size) : undef;
109 });
110  
111 $ffi->attach( [ free => 'DESTROY' ] => ['archive_entry'] => sub {
112 my($xsub, $self) = @_;
113 return if $self->{owner} # owned by another object
114 || ${^GLOBAL_PHASE} eq 'DESTRUCT'; # during global shutdown the xsub might go away
115 $xsub->($self);
116 });
117  
118 #$ffi->attach( [ free => 'DESTROY' ] => ['archive_entry'] => 'void' );
119  
120 $ffi->ignore_not_found(1);
121  
122 $ffi->attach_cast(_digest_type_to_int => archive_entry_digest_t => 'int' );
123  
124 my @size = (
125 undef,
126 16,
127 20,
128 20,
129 32,
130 48,
131 64,
132 );
133  
134 $ffi->attach( digest => ['archive_entry', 'archive_entry_digest_t'] => 'opaque' => sub {
135 my($xsub, $self, $type) = @_;
136 my $size = $size[_digest_type_to_int($type)];
137 my $ptr = $xsub->($self, $type);
138 buffer_to_scalar($ptr, $size);
139 });
140  
141 $ffi->ignore_not_found(0);
142  
143  
144 require Archive::Libarchive::Lib::Entry unless $Archive::Libarchive::no_gen;
145  
146 1;
147  
148 __END__
« blib/lib/Archive/Libarchive/DiskWrite.pm ↑ Summary blib/lib/Archive/Libarchive/EntryLinkResolver.pm »