ifdef

 view release on metacpan or  search on metacpan

lib/ifdef.pm  view on Meta::CPAN

                    $INPOD=      0;
                }

                # not activating now
                else {
                    $_= $ACTIVATING ? "}$/" : $/;
                    $ACTIVATING= 0;
                    $INPOD=      1;
                }
            }

            # normal begin of pod
            else {
                $_= $/;
                $INPOD= 1;
            }
        }

        # at the end of a possibly activated section
        elsif ( $1 eq 'end' ) {
            $_ = $ACTIVATING ? "}$/" : $/;
            $ACTIVATING= 0;
            $INPOD=      1;
        }

        # it's another pod directive
        else {
            $_= $/;
            $INPOD= 1;
        }
    }

    # already inside pod
    elsif ($INPOD) {
        $_= $/;
    }

    # looks like comment, make it normal line if so indicated
    elsif ( m/^#\s+([A-Z_0-9]+)\b/ ) {
         s/^#\s+(?:[A-Z_0-9]+)\b// if $ENV{$1};
    }

    # let the world know if we should
    print STDERR ">$_" if DIFF;
} #oneline

#---------------------------------------------------------------------------

# Perl specific subroutines

#---------------------------------------------------------------------------
#  IN: 1 class (ignored)
#      2..N keys to watch for

sub import {

    # being called from source (unless it's from the test-suite)
    warn "The '".
          __PACKAGE__.
          "' pragma is not supposed to be called from source\n"
           if ( (caller)[2] ) and ( $_[0] ne '_testing_' and !shift );

    # lose the class
    shift;

    # check all parameters
    my @ignored;
    foreach (@_) {
        # it's all
        if ( m#^:?all$# ) {
            $ALL= 1;
        }

        # not all
        elsif ( m#^:?selected$# ) {
            $ALL= 0;
        }

        # looks like an environment var reference
        elsif ( m#^[A-Z_0-9]+$# ) {
            $ENV{$_}= 1;
        }

        # huh?
        else {
            push @ignored, $_;
        }
    }

    # huh?
    warn "Ignored parameters: @ignored\n" if @ignored;

    # make sure we start with a clean slate
    &reset;

    # set up source filter
    return Filter::Util::Call::filter_add( sub {
        if ( ( $STATUS= Filter::Util::Call::filter_read() ) > 0 ) {
            &oneline;
        }
        $STATUS;
    } );
} #import

#---------------------------------------------------------------------------

__END__

=head1 NAME

ifdef - conditionally enable text within pod sections as code

=head1 SYNOPSIS

  export DEBUGGING=1
  perl -Mifdef yourscript.pl

 or:

  perl -Mifdef=VERBOSE yourscript.pl



( run in 2.464 seconds using v1.01-cache-2.11-cpan-a49fcb8fa48 )