diff options
Diffstat (limited to 'lib/App/Acmeman/Source/File.pm')
-rw-r--r-- | lib/App/Acmeman/Source/File.pm | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/App/Acmeman/Source/File.pm b/lib/App/Acmeman/Source/File.pm index 561c279..48a4010 100644 --- a/lib/App/Acmeman/Source/File.pm +++ b/lib/App/Acmeman/Source/File.pm @@ -5,22 +5,32 @@ use warnings; use Carp; use File::Spec; use parent 'App::Acmeman::Source'; +use Getopt::Long qw(GetOptionsFromArray :config gnu_getopt no_ignore_case); sub new { my $class = shift; my $pattern = shift || croak "file name or globbing pattern must be given"; my $ignore = '^\.|~$|\.bak$|^#.*#$'; + my $host; + GetOptionsFromArray(\@_, + 'ignore|i=s' => \$ignore, + 'host|h=s' => \$host); unless ($pattern =~ m{[][*?]}) { $pattern =~ s{/$}{}; $pattern = File::Spec->catfile($pattern, '*'); } - bless { pattern => $pattern, ignore => $ignore }, $class; + bless { pattern => $pattern, + ignore => $ignore, + host => $host }, $class; } sub scan { my ($self) = @_; $self->debug(1, "initializing file list from $self->{pattern}"); my $err = 0; + if ($self->{host}) { + $self->define_domain($self->{host}); + } foreach my $file (glob $self->{pattern}) { next if $file =~ m{$self->{ignore}}; $err |= $self->load($file); @@ -35,12 +45,16 @@ sub load { or do { $self->error("can't open $file: $!"); return 0; - }; + }; chomp(my @lines = <$fh>); close $fh; - my $cn = shift @lines; - $self->define_domain($cn); - $self->define_alias($cn, @lines); + if ($self->{host}) { + $self->define_alias($self->{host}, @lines); + } else { + my $cn = shift @lines; + $self->define_domain($cn); + $self->define_alias($cn, @lines); + } return 1; } |