blib/lib/MYDan/Util/XTar.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 52 CC 4 SCAR 18.3
CC
4
Cov
0%
new
12.0
xtar
6.0
BEGIN
2.0
CRAP 6.2
1 package MYDan::Util::XTar;
2 use strict;
3 use warnings;
4 use Carp;
5 use Tie::File;
6  
7 $|++;
8  
9 my @script = (
10 '#!/bin/bash',
11 'RUN="$0.run"',
12 'export TMP="$RUN.tmp"',
13 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH',
14 'SKIP=$((SIZE+1))',
15 'dd if=$0 of=$RUN skip=1 bs=1024 count=SIZE || exit 1',
16 'dd if=$0 of=$TMP skip=$SKIP bs=1024 || exit 1',
17 'chmod +x $RUN',
18 '$RUN $@',
19 'EXIT=$?',
20 'rm $RUN $TMP',
21 'exit $EXIT',
22 );
23  
24 sub new
25 {
26 my ( $class, %self ) = @_;
27 map{ die "$_ undef\n" unless $self{$_} } qw( script package output );
28 map{ die "nofile: $self{$_}\n" unless -f $self{$_} } qw( script package );
29 bless \%self, ref $class || $class;
30 }
31  
32 sub xtar
33 {
34 my $this = shift;
35 my ( $s, $p, $o ) = @$this{qw( script package output )};
36  
37 my $size = int((stat $s)[7]/1024)+1;
38 my $skip = $size +1;
39 map{ $_ =~ s/SIZE/$size/g }@script;
40  
41 die "tie $o fail: $!!" unless tie my @cont, 'Tie::File', $o;
42 @cont = @script;
43 untie @cont;
44  
45 system "dd if=$s of=$o bs=1024 seek=1 && dd if=$p of=$o seek=$skip bs=1024";
46 chmod 0755, $o;
47 }
48  
49  
50  
51 1;
52 __END__