~ubuntu-branches/ubuntu/saucy/libnamespace-clean-perl/saucy-proposed

« back to all changes in this revision

Viewing changes to inc/Module/AutoInstall.pm

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Yu, Jonathan Yu, Nathan Handler
  • Date: 2010-01-14 16:37:20 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100114163720-zxylq3d3dd4x3fpq
Tags: 0.12-1
[ Jonathan Yu ]
* New upstream release
* Update dependencies per upstream
* Add myself to Uploaders and Copyright
* Standards-Version 3.8.3 (drop perl version dep)
* Use debhelper 7.2.13 for AutoInstall
* Rewrite control description
* Update copyright information to DEP5 format
* Use new short debhelper rules format
* Add patch to correct spelling errors
* Now depends on Test::More 0.88

[ Nathan Handler ]
* debian/watch: Update to ignore development releases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
# various lexical flags
20
20
my ( @Missing, @Existing,  %DisabledTests, $UnderCPAN,     $HasCPANPLUS );
21
 
my ( $Config,  $CheckOnly, $SkipInstall,   $AcceptDefault, $TestOnly );
 
21
my (
 
22
    $Config, $CheckOnly, $SkipInstall, $AcceptDefault, $TestOnly, $AllDeps
 
23
);
22
24
my ( $PostambleActions, $PostambleUsed );
23
25
 
24
26
# See if it's a testing or non-interactive session
73
75
        elsif ( $arg =~ /^--test(?:only)?$/ ) {
74
76
            $TestOnly = 1;
75
77
        }
 
78
        elsif ( $arg =~ /^--all(?:deps)?$/ ) {
 
79
            $AllDeps = 1;
 
80
        }
76
81
    }
77
82
}
78
83
 
115
120
        )[0]
116
121
    );
117
122
 
 
123
    # We want to know if we're under CPAN early to avoid prompting, but
 
124
    # if we aren't going to try and install anything anyway then skip the
 
125
    # check entirely since we don't want to have to load (and configure)
 
126
    # an old CPAN just for a cosmetic message
 
127
 
 
128
    $UnderCPAN = _check_lock(1) unless $SkipInstall;
 
129
 
118
130
    while ( my ( $feature, $modules ) = splice( @args, 0, 2 ) ) {
119
131
        my ( @required, @tests, @skiptests );
120
132
        my $default  = 1;
163
175
            }
164
176
 
165
177
            # XXX: check for conflicts and uninstalls(!) them.
166
 
            if (
167
 
                defined( my $cur = _version_check( _load($mod), $arg ||= 0 ) ) )
 
178
            my $cur = _load($mod);
 
179
            if (_version_cmp ($cur, $arg) >= 0)
168
180
            {
169
181
                print "loaded. ($cur" . ( $arg ? " >= $arg" : '' ) . ")\n";
170
182
                push @Existing, $mod => $arg;
171
183
                $DisabledTests{$_} = 1 for map { glob($_) } @skiptests;
172
184
            }
173
185
            else {
174
 
                print "missing." . ( $arg ? " (would need $arg)" : '' ) . "\n";
 
186
                if (not defined $cur)   # indeed missing
 
187
                {
 
188
                    print "missing." . ( $arg ? " (would need $arg)" : '' ) . "\n";
 
189
                }
 
190
                else
 
191
                {
 
192
                    # no need to check $arg as _version_cmp ($cur, undef) would satisfy >= above
 
193
                    print "too old. ($cur < $arg)\n";
 
194
                }
 
195
 
175
196
                push @required, $mod => $arg;
176
197
            }
177
198
        }
184
205
            !$SkipInstall
185
206
            and (
186
207
                $CheckOnly
 
208
                or ($mandatory and $UnderCPAN)
 
209
                or $AllDeps
187
210
                or _prompt(
188
211
                    qq{==> Auto-install the }
189
212
                      . ( @required / 2 )
214
237
        }
215
238
    }
216
239
 
217
 
    $UnderCPAN = _check_lock();    # check for $UnderCPAN
218
 
 
219
240
    if ( @Missing and not( $CheckOnly or $UnderCPAN ) ) {
220
241
        require Config;
221
242
        print
234
255
    *{'main::WriteMakefile'} = \&Write if caller(0) eq 'main';
235
256
}
236
257
 
 
258
sub _running_under {
 
259
    my $thing = shift;
 
260
    print <<"END_MESSAGE";
 
261
*** Since we're running under ${thing}, I'll just let it take care
 
262
    of the dependency's installation later.
 
263
END_MESSAGE
 
264
    return 1;
 
265
}
 
266
 
237
267
# Check to see if we are currently running under CPAN.pm and/or CPANPLUS;
238
268
# if we are, then we simply let it taking care of our dependencies
239
269
sub _check_lock {
240
 
    return unless @Missing;
 
270
    return unless @Missing or @_;
 
271
 
 
272
    my $cpan_env = $ENV{PERL5_CPAN_IS_RUNNING};
241
273
 
242
274
    if ($ENV{PERL5_CPANPLUS_IS_RUNNING}) {
243
 
        print <<'END_MESSAGE';
244
 
 
245
 
*** Since we're running under CPANPLUS, I'll just let it take care
246
 
    of the dependency's installation later.
247
 
END_MESSAGE
248
 
        return 1;
249
 
    }
250
 
 
251
 
    _load_cpan();
 
275
        return _running_under($cpan_env ? 'CPAN' : 'CPANPLUS');
 
276
    }
 
277
 
 
278
    require CPAN;
 
279
 
 
280
    if ($CPAN::VERSION > '1.89') {
 
281
        if ($cpan_env) {
 
282
            return _running_under('CPAN');
 
283
        }
 
284
        return; # CPAN.pm new enough, don't need to check further
 
285
    }
 
286
 
 
287
    # last ditch attempt, this -will- configure CPAN, very sorry
 
288
 
 
289
    _load_cpan(1); # force initialize even though it's already loaded
252
290
 
253
291
    # Find the CPAN lock-file
254
292
    my $lock = MM->catfile( $CPAN::Config->{cpan_home}, ".lock" );
284
322
    while ( my ( $pkg, $ver ) = splice( @_, 0, 2 ) ) {
285
323
 
286
324
        # grep out those already installed
287
 
        if ( defined( _version_check( _load($pkg), $ver ) ) ) {
 
325
        if ( _version_cmp( _load($pkg), $ver ) >= 0 ) {
288
326
            push @installed, $pkg;
289
327
        }
290
328
        else {
313
351
        @modules = @newmod;
314
352
    }
315
353
 
316
 
    if ( _has_cpanplus() ) {
 
354
    if ( _has_cpanplus() and not $ENV{PERL_AUTOINSTALL_PREFER_CPAN} ) {
317
355
        _install_cpanplus( \@modules, \@config );
318
356
    } else {
319
357
        _install_cpan( \@modules, \@config );
323
361
 
324
362
    # see if we have successfully installed them
325
363
    while ( my ( $pkg, $ver ) = splice( @modules, 0, 2 ) ) {
326
 
        if ( defined( _version_check( _load($pkg), $ver ) ) ) {
 
364
        if ( _version_cmp( _load($pkg), $ver ) >= 0 ) {
327
365
            push @installed, $pkg;
328
366
        }
329
367
        elsif ( $args{do_once} and open( FAILED, '>> .#autoinstall.failed' ) ) {
378
416
        my $success;
379
417
        my $obj = $modtree->{$pkg};
380
418
 
381
 
        if ( $obj and defined( _version_check( $obj->{version}, $ver ) ) ) {
 
419
        if ( $obj and _version_cmp( $obj->{version}, $ver ) >= 0 ) {
382
420
            my $pathname = $pkg;
383
421
            $pathname =~ s/::/\\W/;
384
422
 
471
509
        my $obj     = CPAN::Shell->expand( Module => $pkg );
472
510
        my $success = 0;
473
511
 
474
 
        if ( $obj and defined( _version_check( $obj->cpan_version, $ver ) ) ) {
 
512
        if ( $obj and _version_cmp( $obj->cpan_version, $ver ) >= 0 ) {
475
513
            my $pathname = $pkg;
476
514
            $pathname =~ s/::/\\W/;
477
515
 
535
573
    my $ver   = shift;
536
574
 
537
575
    return
538
 
      if defined( _version_check( _load($class), $ver ) );  # no need to upgrade
 
576
      if _version_cmp( _load($class), $ver ) >= 0;  # no need to upgrade
539
577
 
540
578
    if (
541
579
        _prompt( "==> A newer version of $class ($ver) is required. Install?",
632
670
 
633
671
# Load CPAN.pm and it's configuration
634
672
sub _load_cpan {
635
 
    return if $CPAN::VERSION;
 
673
    return if $CPAN::VERSION and $CPAN::Config and not @_;
636
674
    require CPAN;
637
675
    if ( $CPAN::HandleConfig::VERSION ) {
638
676
        # Newer versions of CPAN have a HandleConfig module
644
682
}
645
683
 
646
684
# compare two versions, either use Sort::Versions or plain comparison
647
 
sub _version_check {
 
685
# return values same as <=>
 
686
sub _version_cmp {
648
687
    my ( $cur, $min ) = @_;
649
 
    return unless defined $cur;
 
688
    return -1 unless defined $cur;  # if 0 keep comparing
 
689
    return 1 unless $min;
650
690
 
651
691
    $cur =~ s/\s+$//;
652
692
 
657
697
            ) {
658
698
 
659
699
            # use version.pm if it is installed.
660
 
            return (
661
 
                ( version->new($cur) >= version->new($min) ) ? $cur : undef );
 
700
            return version->new($cur) <=> version->new($min);
662
701
        }
663
702
        elsif ( $Sort::Versions::VERSION or defined( _load('Sort::Versions') ) )
664
703
        {
665
704
 
666
705
            # use Sort::Versions as the sorting algorithm for a.b.c versions
667
 
            return ( ( Sort::Versions::versioncmp( $cur, $min ) != -1 )
668
 
                ? $cur
669
 
                : undef );
 
706
            return Sort::Versions::versioncmp( $cur, $min );
670
707
        }
671
708
 
672
709
        warn "Cannot reliably compare non-decimal formatted versions.\n"
675
712
 
676
713
    # plain comparison
677
714
    local $^W = 0;    # shuts off 'not numeric' bugs
678
 
    return ( $cur >= $min ? $cur : undef );
 
715
    return $cur <=> $min;
679
716
}
680
717
 
681
718
# nothing; this usage is deprecated.
706
743
      if $Config;
707
744
 
708
745
    $PostambleActions = (
709
 
        $missing
 
746
        ($missing and not $UnderCPAN)
710
747
        ? "\$(PERL) $0 --config=$config --installdeps=$missing"
711
748
        : "\$(NOECHO) \$(NOOP)"
712
749
    );
746
783
sub postamble {
747
784
    $PostambleUsed = 1;
748
785
 
749
 
    return << ".";
 
786
    return <<"END_MAKE";
750
787
 
751
788
config :: installdeps
752
789
\t\$(NOECHO) \$(NOOP)
757
794
installdeps ::
758
795
\t$PostambleActions
759
796
 
760
 
.
 
797
END_MAKE
761
798
 
762
799
}
763
800
 
765
802
 
766
803
__END__
767
804
 
768
 
#line 1003
 
805
#line 1056