6 require Packaging
::Tools
;
8 require File
::Basename
;
17 MAKE
=> '/usr/pkg/bin/bmake',
18 PKG_INFO_CMD
=> '/usr/pkg/sbin/pkg_info',
19 PKGSRCDIR
=> '/data/pkgsrc',
22 #my $pkgdist = '@pkgdist@';
23 my $pkgdist = 'pkgsrc';
26 my $pkgtool = Packaging
::Tools
->new( $pkgdist, \
%tools );
28 my @templates = $pkgtool->find_templates("pkg4module");
29 my %tpl_names = map { scalar File
::Basename
::fileparse
( $_, qr/\.[^.]*/ ) => $_ } @templates;
30 my %opts = ( "update-cpan-index" => 0 );
31 my @fmt_options = map { "output-" . $_ } keys %tpl_names;
33 ( map { $_ . ":s" } @fmt_options ),
34 "cpan-home=s", "update-cpan-index!", "module=s@", "help|h", "usage|?"
37 GetOptions
( \
%opts, @options ) or pod2usage
(2);
39 defined( $opts{help
} )
47 defined( $opts{usage
} ) and $opts{usage
} and pod2usage
(1);
48 defined( $opts{module
} ) or pod2usage
(1);
50 my @output = grep { defined( $opts{$_} ) } @fmt_options;
51 @output or @output = ('output-log');
53 $pkgtool->load_cpan_config( $opts{"cpan-home"} );
54 $pkgtool->get_cpan_versions( $opts{"update-cpan-index"} );
56 my ( $up_to_date, $need_update, $need_check ) = (0) x
3;
57 my %pkglist = map { $_ => 1 } $pkgtool->find_packaged_modules();
60 my @modules = split( ",", join( ",", @
{ $opts{module
} } ) );
61 foreach my $module (@modules)
63 printf( "Searching for %s\n", $module );
64 push( @distris, $pkgtool->get_distribution_for_module($module) );
68 print Dumper \
@distris;
71 my $template = Template
->new(
72 INCLUDE_PATH
=> join( ":",
73 $pkgtool->get_template_directories("pkg4module"),
74 $pkgtool->get_template_directories() ),
77 my %vars = ( data
=> \
@distris, );
78 foreach my $tgt (@output)
80 my $tgtfn = $opts{$tgt};
81 ( my $tpl = $tgt ) =~ s/output-(.*)/$1/;
84 # for backward compatibility
85 ( my $ext = $tgt ) =~ s/output-([^-]+).*/$1/;
86 $tgtfn = File
::Spec
->catfile( $ENV{HOME
}, "pkg4module." . $ext );
88 $template->process( $tpl_names{$tpl}, \
%vars, $tgtfn )
89 or die die $template->error();