| 1 | package XML::OBEXFTP::FolderListing; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 4 | our $VERSION = '1.001002'; # VERSION | |||||||||
| 7 | |||||||||||
| 8 | 4 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 4 | ▶ | use XML::Simple; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 4 | ▶ | use base 'Class::Accessor::Grouped'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 4 | __PACKAGE__->mk_group_accessors( | |||||||||
| 12 | simple => qw(folders files parent_folder tree) | ||||||||||
| 13 | ); | ||||||||||
| 14 | |||||||||||
| 15 | 2 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 16 | 2 | return bless {}, shift; | |||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | 1 | ▶ | sub parse { | ||||||||
|
Subroutine
parse: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 20 | 1 | my ( $self, $data ) = @_; | |||||||||
| 21 | return undef | ||||||||||
| 22 | 1 | ▶ | unless defined $data; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 1 | my $parse_ref = XMLin($data,ForceArray => [ 'folder', 'file' ] ); | |||||||||
| 24 | 1 | $parse_ref->{parent_folder} = delete $parse_ref->{'parent-folder'}; | |||||||||
| 25 | 1 | $self->parent_folder( $parse_ref->{parent_folder} ); | |||||||||
| 26 | |||||||||||
| 27 | 1 | $self->folders( [ keys %{ $parse_ref->{folder} } ] ); | |||||||||
| 28 | 1 | $self->files( [ keys %{ $parse_ref->{file} } ] ); | |||||||||
| 29 | 1 | return $self->tree( $parse_ref ); | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 2 | ▶ | sub is_folder { | ||||||||
|
Subroutine
is_folder: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 33 | 2 | my ( $self, $name ) = @_; | |||||||||
| 34 | |||||||||||
| 35 | 2 | my $tree = $self->tree; | |||||||||
| 36 | 2 | ▶ | return exists $tree->{folder}{ $name } ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 2 | ▶ | sub is_file { | ||||||||
|
Subroutine
is_file: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 40 | 2 | my ( $self, $name ) = @_; | |||||||||
| 41 | |||||||||||
| 42 | 2 | my $tree = $self->tree; | |||||||||
| 43 | 2 | ▶ | return exists $tree->{file}{ $name } ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 2 | ▶ | sub info { | ||||||||
|
Subroutine
info: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 47 | 2 | my ( $self, $name, $type ) = @_; | |||||||||
| 48 | 2 | ▶ | $type = 'file' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | unless defined $type; | ||||||||||
| 50 | |||||||||||
| 51 | 2 | my $info = $self->tree->{ $type }{ $name }; | |||||||||
| 52 | 2 | $info->{perms} = delete $info->{'user-perm'}; | |||||||||
| 53 | 2 | $info->{modified_sane} = $self->modified_sane( $name, $type ); | |||||||||
| 54 | 2 | return $info; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 2 | ▶ | sub perms { | ||||||||
|
Subroutine
perms: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 58 | 2 | my ( $self, $name, $type ) = @_; | |||||||||
| 59 | 2 | ▶ | $type = 'file' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | unless defined $type; | ||||||||||
| 61 | |||||||||||
| 62 | 2 | return $self->tree->{ $type }{ $name }{'user-perm'}; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 1 | ▶ | sub size { | ||||||||
|
Subroutine
size: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 66 | 1 | my ( $self, $name ) = @_; | |||||||||
| 67 | 1 | return $self->tree->{file}{ $name }{size}; | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 7 | ▶ | sub type { | ||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 71 | 7 | my ( $self, $name ) = @_; | |||||||||
| 72 | 7 | return $self->tree->{file}{ $name }{type}; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 6 | ▶ | sub modified { | ||||||||
|
Subroutine
modified: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 76 | 6 | my ( $self, $name, $type ) = @_; | |||||||||
| 77 | 6 | ▶ | $type = 'file' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | unless defined $type; | ||||||||||
| 79 | |||||||||||
| 80 | 6 | return $self->tree->{ $type }{ $name }{modified}; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 4 | ▶ | sub modified_sane { | ||||||||
|
Subroutine
modified_sane: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 84 | 4 | my $self = shift; | |||||||||
| 85 | 4 | my $time = $self->modified( @_ ); | |||||||||
| 86 | return undef | ||||||||||
| 87 | 4 | ▶ | unless defined $time; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | 4 | my %time; | |||||||||
| 89 | 4 | @time{ qw(year month day hour minute second) } | |||||||||
| 90 | = $time =~ /(\d{4})(\d{2})(\d{2})\w(\d{2})(\d{2})(\d{2})/; | ||||||||||
| 91 | 4 | return \%time; | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | 4 | 1; | |||||||||
| 95 | |||||||||||
| 96 | __END__ | ||||||||||