Transform -> Moo
[Packaging-Tools.git] / scriptlet / pkg4module.pl
blobab1ffbb27b427e97659956e74563813ae875e737
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 require Packaging::Tools;
8 require File::Basename;
9 require File::Spec;
11 use Getopt::Long;
12 use Pod::Usage;
13 use Template;
15 my %tools = (
16 #@toolhash@
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';
25 my @pkgs_in_state;
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;
32 my @options = (
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} )
40 and $opts{help}
41 and pod2usage(
43 -verbose => 2,
44 -exitval => 0
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();
59 my @distris;
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) );
67 use Data::Dumper;
68 print Dumper \@distris;
69 exit(0);
71 my $template = Template->new(
72 INCLUDE_PATH => join( ":",
73 $pkgtool->get_template_directories("pkg4module"),
74 $pkgtool->get_template_directories() ),
75 ABSOLUTE => 1,
77 my %vars = ( data => \@distris, );
78 foreach my $tgt (@output)
80 my $tgtfn = $opts{$tgt};
81 ( my $tpl = $tgt ) =~ s/output-(.*)/$1/;
82 unless ($tgtfn)
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();
92 exit(0);