SFTP/Attributes.pm

filter: Statementstmt 26.3% 19 / 72 Branchbran 0.0% 0 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 55.5% 5 / 9 Podpod 66.6% 2 / 3 totaltotal 24.0% 26 / 108 SCAR 48.8
CC
15
Cov
20%
init
110.0
as_buffer
30.0
__ANON__
6.0
CRAP 131.1
« SFTP.pm ↑ Summary SFTP/Constants.pm »
1 # $Id: Attributes.pm,v 1.5 2001/05/16 01:38:01 btrott Exp $
2  
3 package Net::SFTP::Attributes;
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Net::SFTP::Constants qw( :att );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Net::SFTP::Buffer;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use vars qw( @FIELDS );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 @FIELDS = qw( flags size uid gid perm atime mtime );
11  
12 2 for my $f (@FIELDS) {
13 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 *$f = sub {
15 0 ▶ my $a = shift;
Subroutine __ANON__: not called CC=2 SCAR=17.9
16 0 ▶ $a->{$f} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
17 0 $a->{$f};
18 14 };
19 }
20  
21 sub new {
22 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
23 0 my $a = bless { }, $class;
24 0 $a->init(@_);
25 }
26  
27 sub init {
28 0 ▶ my $a = shift;
Subroutine init: not called CC=10 SCAR=47.0
Pod undocumented
29 0 my %param = @_;
30 0 for my $f (@FIELDS) {
31 0 $a->{$f} = 0;
32 }
33 0 ▶ if (my $stat = $param{Stat}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $stat = $param{'Stat'}) { } 0 0 0
elsif (my $buf = $param{'Buffer'}) { } 0 0 0
34 0 $a->{flags} |= SSH2_FILEXFER_ATTR_SIZE;
35 0 $a->{size} = $stat->[7];
36 0 $a->{flags} |= SSH2_FILEXFER_ATTR_UIDGID;
37 0 $a->{uid} = $stat->[4];
38 0 $a->{gid} = $stat->[5];
39 0 $a->{flags} |= SSH2_FILEXFER_ATTR_PERMISSIONS;
40 0 $a->{perm} = $stat->[2];
41 0 $a->{flags} |= SSH2_FILEXFER_ATTR_ACMODTIME;
42 0 $a->{atime} = $stat->[8];
43 0 $a->{mtime} = $stat->[9];
44 }
45 elsif (my $buf = $param{Buffer}) {
46 0 $a->{flags} = $buf->get_int32;
47 0 ▶ if ($a->{flags} & SSH2_FILEXFER_ATTR_SIZE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a->{"flags"} & &SSH2_FILEXFER_ATTR_SIZE()) 0 0 0
48 0 $a->{size} = $buf->get_int64;
49 }
50 0 ▶ if ($a->{flags} & SSH2_FILEXFER_ATTR_UIDGID) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a->{"flags"} & &SSH2_FILEXFER_ATTR_UIDGID()) 0 0 0
51 0 $a->{uid} = $buf->get_int32;
52 0 $a->{gid} = $buf->get_int32;
53 }
54 0 ▶ if ($a->{flags} & SSH2_FILEXFER_ATTR_PERMISSIONS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a->{"flags"} & &SSH2_FILEXFER_ATTR_PERMISSIONS()) 0 0 0
55 0 $a->{perm} = $buf->get_int32;
56 }
57 0 ▶ if ($a->{flags} & SSH2_FILEXFER_ATTR_ACMODTIME) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a->{"flags"} & &SSH2_FILEXFER_ATTR_ACMODTIME()) 0 0 0
58 0 $a->{atime} = $buf->get_int32;
59 0 $a->{mtime} = $buf->get_int32;
60 }
61 0 ▶ if ($a->{flags} & SSH2_FILEXFER_ATTR_EXTENDED) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a->{"flags"} & &SSH2_FILEXFER_ATTR_EXTENDED()) 0 0 0
62 0 my $extended_count = $buf->get_int32;
63 0 for (1..$extended_count) {
64 0 my $name = $buf->get_str;
65 0 my $value = $buf->get_str;
66 0 $a->{$name} = $value;
67 }
68 }
69 }
70 0 $a;
71 }
72  
73 sub as_buffer {
74 0 ▶ my $a = shift;
Subroutine as_buffer: not called CC=5 SCAR=34.0
Pod documented
75 0 my $buf = Net::SFTP::Buffer->new;
76 0 $buf->put_int32($a->{flags});
77 0 ▶ if ($a->{flags} & SSH2_FILEXFER_ATTR_SIZE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a->{"flags"} & &SSH2_FILEXFER_ATTR_SIZE()) 0 0 0
78 0 $buf->put_int64(int $a->{size});
79 }
80 0 ▶ if ($a->{flags} & SSH2_FILEXFER_ATTR_UIDGID) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a->{"flags"} & &SSH2_FILEXFER_ATTR_UIDGID()) 0 0 0
81 0 $buf->put_int32($a->{uid});
82 0 $buf->put_int32($a->{gid});
83 }
84 0 ▶ if ($a->{flags} & SSH2_FILEXFER_ATTR_PERMISSIONS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a->{"flags"} & &SSH2_FILEXFER_ATTR_PERMISSIONS()) 0 0 0
85 0 $buf->put_int32($a->{perm});
86 }
87 0 ▶ if ($a->{flags} & SSH2_FILEXFER_ATTR_ACMODTIME) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a->{"flags"} & &SSH2_FILEXFER_ATTR_ACMODTIME()) 0 0 0
88 0 $buf->put_int32($a->{atime});
89 0 $buf->put_int32($a->{mtime});
90 }
91 0 $buf;
92 }
93  
94 2 1;
95 __END__
« SFTP.pm ↑ Summary SFTP/Constants.pm »