File Coverage

blib/lib/OTRS/OPM/Maker/Command/filetest.pm
Criterion Covered Total %
statement 48 48 100.0
branch 8 8 100.0
condition 12 12 100.0
subroutine 10 10 100.0
pod 4 4 100.0
total 82 82 100.0


line stmt bran cond sub pod time code
1             package OTRS::OPM::Maker::Command::filetest;
2             $OTRS::OPM::Maker::Command::filetest::VERSION = '0.18';
3             # ABSTRACT: check if filelist in .sopm includes the files on your disk
4              
5 14     14   10930 use strict;
  14         35  
  14         460  
6 14     14   76 use warnings;
  14         27  
  14         389  
7              
8 14     14   6909 use File::Find::Rule;
  14         104027  
  14         137  
9 14     14   2835 use Path::Class ();
  14         134095  
  14         294  
10 14     14   3073 use XML::LibXML;
  14         206225  
  14         100  
11              
12 14     14   3920 use OTRS::OPM::Maker -command;
  14         36  
  14         144  
13              
14             sub abstract {
15 1     1 1 3519 return "Check if filelist in .sopm includes the files on your disk";
16             }
17              
18             sub usage_desc {
19 1     1 1 947 return "opmbuild filetest ";
20             }
21              
22             sub validate_args {
23 8     8 1 8266 my ($self, $opt, $args) = @_;
24            
25 8 100 100     139 $self->usage_error( 'need path to .sopm' ) if
      100        
      100        
      100        
26             !$args or
27             'ARRAY' ne ref $args or
28             !defined $args->[0] or
29             $args->[0] !~ /\.sopm\z/ or
30             !-f $args->[0];
31             }
32              
33             sub execute {
34 2     2 1 2951 my ($self, $opt, $args) = @_;
35            
36 2         21 my $file = $args->[0];
37 2         32 my $parser = XML::LibXML->new;
38 2         57 my $tree = $parser->parse_file( $file );
39            
40 2         981 my $sopm_path = Path::Class::File->new( $file );
41 2         447 my $path = $sopm_path->dir;
42            
43 2         45 my $path_str = $path->stringify;
44 2         122 my $ignore_files = File::Find::Rule->file->name(".*");
45 2         390 my @files_in_fs = File::Find::Rule->file
46             ->not( $ignore_files )
47             ->in ( $path_str );
48            
49 6         57 my %fs = map{ $_ =~ s{\A\Q$path_str\E/?}{}; $_ => 1 }
  6         23  
50 2         2755 grep{ $_ !~ /\.git|CVS|svn/ }@files_in_fs;
  6         30  
51            
52 2         15 delete $fs{ $sopm_path->basename };
53            
54 2         39 my $root_elem = $tree->getDocumentElement;
55            
56             # retrieve file information
57 2         86 my @files = $root_elem->findnodes( 'Filelist/File' );
58            
59 2         190 my @not_found;
60            
61             FILE:
62 2         7 for my $file ( @files ) {
63 4         25 my $name = $file->findvalue( '@Location' );
64            
65 4 100       559 push @not_found, $name if !delete $fs{$name};
66             }
67            
68 2 100       9 if ( @not_found ) {
69             print "Files listed in .sopm but not found on disk:\n",
70 1         4 map{ " - $_\n" }@not_found;
  2         64  
71             }
72            
73 2 100       18 if ( %fs ) {
74             print "Files found on disk but not listed in .sopm:\n",
75 1         11 map{ " - $_\n" }sort keys %fs;
  2         29  
76             }
77             }
78              
79             1;
80              
81             __END__