ctflags::config - configure ctflags


ctflags documentation Contained in the ctflags distribution.

Index


Code Index:

NAME

Top

ctflags::config - configure ctflags

SYNOPSIS

Top

  use ctflags::config long => 'foo:long_name=f',
                      restriction => 'foo:bar';

ABSTRACT

Top

ctflags::config configure ctflags allowing to define aliases and to restrict which ctflags can be used.

DESCRIPTION

Top

LONG NAMES

To create long aliases for flags use the alias or long key when 'using' the package:

  use ctflags::config alias => 'foo:long_name=f';

makes foo:long_name take the same value as foo:f.

Long flag names are usable with the ctflags::long module.

RESTRICTING FLAGS

The restriction keyword allos to limit the flags that are valid inside a namespace. i.e.

  use ctflags::config restriction => 'foo:bar';

limits the valid flag names in the namespace foo to be b, c<A> and r, trying to use any other name will cause an exception.

EXPORT

None.

SEE ALSO

Top

ctflags, ctflags::long.

AUTHOR

Top

Salvador Fandi&241;o Garcia, <sfandino@yahoo.com>.

COPYRIGHT AND LICENSE

Top


ctflags documentation Contained in the ctflags distribution.

package ctflags::config;

our $VERSION = '0.01';

use 5.006;
use strict;
use warnings;
use Carp;

use ctflags::memory;
use ctflags::check;

sub arrayorsplit ($ ) {
  my $val=shift;
  return @{$val} if 'ARRAY' eq ref $val;
  return split /[\s,]+/, $val;
}

sub import {
  my $self=shift;
  eval {
    while (@_) {
      my $key=shift;
      if ($key eq 'alias' or $key eq 'long') {
	my $alias=shift;
	check_defopt $alias, 'alias';
	foreach (arrayorsplit $alias) {
	  if ( m{^
		 		 ($ns_re)    # $1=namespace
		 		 :
		 		 ($identifier_re) # $2=name
		 		 =
		 		 ($flag_re)  # $3=flag
		 		 $
				}x ) {
	    set_ctflag_alias $1, $2, $3;
	  }
	  else {
	    die "invalid alias specification '$_'\n";
	  }
	}
      }
      elsif ($key eq 'restriction') {
	my $rest=shift;
	check_defopt $rest, 'restriction';
	foreach (arrayorsplit $rest) {
	  if (m{^
				($ns_re)    # $1=namespace
				:
				($flagset_re) # $2=flagset
				$
	       	       }x ) {
	    restrict_ctflags $1, $2;
	  }
	  else {
	    die "invalid restriction specification '$_'\n";
	  }
	}
      }
      else {
	die "unknow option '$key'\n";
      }
    }
  };
  if ($@) { chomp $@; croak $@ };
}


1;
__END__