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