| 1 | package XT::Files::Plugin::Dirs; | ||
| 2 | |||
| 3 | use 5.006; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | our $VERSION = '0.001'; | ||
| 8 | |||
| 9 | use parent 'XT::Files::Plugin'; | ||
| 10 | |||
| 11 | sub run { | ||
| 12 | my ( $self, $args ) = @_; | ||
| 13 | |||
| 14 | my @dirs; | ||
| 15 | |||
| 16 | ARG: | ||
| 17 | for my $arg ( @{$args} ) { | ||
| 18 | my ( $key, $value ) = @{$arg}; | ||
| 19 | |||
| 20 | if ( ( $key eq 'bin' ) || ( $key eq 'module' ) || ( $key eq 'test' ) ) { | ||
| 21 | push @dirs, $arg; | ||
| 22 | next ARG; | ||
| 23 | } | ||
| 24 | |||
| 25 | $self->log_fatal("Invalid configuration option '$key = $value' for plugin 'Dirs'"); | ||
| 26 | } | ||
| 27 | |||
| 28 | my $xtf = $self->xtf; | ||
| 29 | |||
| 30 | # We sort the dirs because e.g. bin/lib must be scanned before bin | ||
| 31 | # because bin_dir() would add every file found. | ||
| 32 | # | ||
| 33 | # By reverse sorting we guarantee that we always scan the most | ||
| 34 | # significant directory first. | ||
| 35 | DIR: | ||
| 36 | for my $dir ( reverse sort { $a->[1] cmp $b->[1] } @dirs ) { | ||
| 37 | my ( $type, $name ) = @{$dir}; | ||
| 38 | |||
| 39 | if ( $type eq 'bin' ) { | ||
| 40 | $xtf->bin_dir($name); | ||
| 41 | next DIR; | ||
| 42 | } | ||
| 43 | |||
| 44 | if ( $type eq 'module' ) { | ||
| 45 | $xtf->module_dir($name); | ||
| 46 | next DIR; | ||
| 47 | } | ||
| 48 | |||
| 49 | if ( $type eq 'test' ) { | ||
| 50 | $xtf->test_dir($name); | ||
| 51 | next DIR; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | return; | ||
| 56 | } | ||
| 57 | |||
| 58 | 1; | ||
| 59 | |||
| 60 | __END__ |