Acme-No

 view release on metacpan or  search on metacpan

No.pm  view on Meta::CPAN

package Acme::No;

use 5.00503;

use Carp qw(croak);
use UNIVERSAL ();

use strict;

use Filter::Util::Call;

$Acme::No::VERSION = '0.03';

sub import {

  filter_add(sub {

    my $status = 0; 

    if (($status = filter_read) > 0) {

      my (undef, $no, $module, $version) = m/(^|;)\s*(no)\s+([\w\-:]*)\s*(\d+[.]?(\d+[._]?)*)/;

      if ($no && $module && $version) {
        # no mod_perl 2.0;
                        
        if ($module eq 'v') {
          # fall through to Perl part if we caught 'no v5.6.0'
        }
        else {

          eval "require $module" or die $@;

          my $modversion = UNIVERSAL::VERSION($module);

          croak "$module version $modversion too high--version less than $version required"
            unless $modversion < $version;

          undef $no;  # we're done
        }
      }

      if ($no && $version) {
        # no 6.0;

        # perl version foo (ugh)
        my ($rev, $ver, $subver) = split '[._]', $version;

        if ($ver > 1000) {              # 5.006001
          $subver = ($ver % 1000);
          $ver = int($ver / 1000);
        }
        elsif ($ver > 100) {            # 5.00503
          $subver = ($ver % 100) * 10;
          $ver = int($ver / 100);
        }
        else {                          # silence undef warnings
          $subver ||= 0;
        }

        $version = $rev + ($ver/1000) + ($subver/1000000);

        croak "Perl v$] too high--version less than v$version required"
          unless $] < $version;
      }

      # wipe away user code so the real perl doesn't
      # barf on our implementation
      s/(no)\s+([\w\-:]*)\s*(\d+[.]?(\d+[._]?)*)//;
    }

    return $status;
  });
}

1;

__END__

=head1 NAME 

Acme::No - makes no() work the way I want it to

=head1 SYNOPSIS

 use 5.6;            # I use our(), so 5.6 is required
 no  6.0;            # but this was coded for perl 5, not perl 6
                     # and the perl 6 compat layer isn't really 5.6
                     # so my code breaks under 6.0

 use mod_perl 1.27;  # we need at least version 1.27
 no mod_perl 2.0;    # but mod_perl 2.0 is entirely different than 1.0
                     # so keep my cpan email to a minimum
                  

=head1 DESCRIPTION

ok, first the appropriate pod:

$ perldoc C<-f> no 
  =item no Module VERSION LIST

  =item no Module VERSION

  =item no Module LIST

  =item no Module

  See the L</use> function, which C<no> is the opposite of.


now, one might think that, since 

 use mod_perl 1.27;

makes sure that mod_perl is at least version 1.27,



( run in 3.639 seconds using v1.01-cache-2.11-cpan-d80b1682f3f )