diff options
| author | fukachan <fukachan> | 2003-07-21 10:40:06 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2003-07-21 10:40:06 +0000 |
| commit | 490545a8496ee167f908d361af780abf1fa608a0 (patch) | |
| tree | 5d7791cccade8cb4731e9d2c421b85c19f52b314 /fml/lib/Mail/Message | |
| parent | b51ce6bd179c2c2cdf52186e9d8dfa3800bfd944 (diff) | |
| download | fml8-490545a8496ee167f908d361af780abf1fa608a0.tar.gz fml8-490545a8496ee167f908d361af780abf1fa608a0.tar.bz2 fml8-490545a8496ee167f908d361af780abf1fa608a0.zip | |
import search_program() into Mail::Message::Utils module.
modified Checksum.pm to use it.
Diffstat (limited to 'fml/lib/Mail/Message')
| -rw-r--r-- | fml/lib/Mail/Message/Checksum.pm | 18 | ||||
| -rw-r--r-- | fml/lib/Mail/Message/Utils.pm | 52 |
2 files changed, 62 insertions, 8 deletions
diff --git a/fml/lib/Mail/Message/Checksum.pm b/fml/lib/Mail/Message/Checksum.pm index 363639b7..87815077 100644 --- a/fml/lib/Mail/Message/Checksum.pm +++ b/fml/lib/Mail/Message/Checksum.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: Checksum.pm,v 1.6 2002/12/22 03:09:56 fukachan Exp $ +# $FML: Checksum.pm,v 1.7 2003/01/26 03:23:09 fukachan Exp $ # package Mail::Message::Checksum; @@ -70,12 +70,16 @@ sub _init $self->{ _type } = 'native'; } else { - # XXX-TODO: hmm, we should remove search_program() dependence? - eval qq{ require File::Utils; import File::Utils qw(search_program);}; - my $prog = search_program('md5') || search_program('md5sum'); - if (defined $prog) { - $self->{ _program } = $prog; - } + eval q{ + use Mail::Message::Utils; + my $prog = Mail::Message::Utils::search_program('md5') || + Mail::Message::Utils::search_program('md5sum'); + + if (defined $prog) { + $self->{ _program } = $prog; + } + }; + carp($@) if $@; } } diff --git a/fml/lib/Mail/Message/Utils.pm b/fml/lib/Mail/Message/Utils.pm index 1085f1dd..4b556d33 100644 --- a/fml/lib/Mail/Message/Utils.pm +++ b/fml/lib/Mail/Message/Utils.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: Utils.pm,v 1.6 2003/07/19 10:23:35 fukachan Exp $ +# $FML: Utils.pm,v 1.7 2003/07/21 04:51:35 fukachan Exp $ # package Mail::Message::Utils; @@ -89,6 +89,56 @@ sub from_to_name } +=head2 C<search_program($file [, $path_list ])> + +search C<$file>. +C<$path_list> is the ARRAY_REF. +It searches it among C<$path_list> if specified. + +The default search path list is + + ('/usr/bin', '/bin', '/sbin', ' /usr/local/bin', + '/usr/gnu/bin', '/usr/pkg/bin') + +=cut + + +# Descriptions: search executable named as $file +# The "path_list" is an ARRAY_REFERENCE. +# For example, +# search_program('md5'); +# search_program('md5', [ '/bin', '/sbin' ]); +# Arguments: STR($file) ARRAY_REF($path_list) +# Side Effects: none +# Return Value: STR +sub search_program +{ + my ($file, $path_list) = @_; + + my $default_path_list = [ + '/usr/bin', + '/bin', + '/sbin', + '/usr/local/bin', + '/usr/gnu/bin', + '/usr/pkg/bin' + ]; + + $path_list ||= $default_path_list; + + use File::Spec; + my $path; + for $path (@$path_list) { + my $prog = File::Spec->catfile($path, $file); + if (-x $prog) { + return $prog; + } + } + + return wantarray ? () : undef; +} + + =head1 CODING STYLE See C<http://www.fml.org/software/FNF/> on fml coding style guide. |
