ctflags::long - use ctflags with long names


ctflags documentation Contained in the ctflags distribution.

Index


Code Index:

NAME

Top

ctflags::long - use ctflags with long names

SYNOPSIS

Top

  use ctflags::long;




ABSTRACT

Top

Reference ctflags with long names instead of using single letters.

DESCRIPTION

Top

After ctflags::config has been used to assign long names to ctflags, this package can be used to import the flags as normal Perl constants but refering to the flags by its long name. i.e.:

  use ctflags::config long => 'foo:bar=b';
  use ctflags::long 'my_bar=foo:bar';

the first line creates an alias for foo:b as foo:bar, the second line imports foo:bar (and so, foo:b) as constant my_bar.

EXPORT

The requested flags

SEE ALSO

Top

ctflags, ctflags::parse, ctflags::config and constant.

AUTHOR

Top

Salva, <salva@nonet>

COPYRIGHT AND LICENSE

Top


ctflags documentation Contained in the ctflags distribution.

package ctflags::long;

our $VERSION = '0.01';

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

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

sub import {
  my $self=shift;
  my ($package)=caller;

  eval {
    while (@_) {
      my $key=shift;
      if (my ($name, $ns, $long)=
	  $key=~m{^
		  		  (?:
		   		   ($identifier_re) # constant name,
		   		   =
		  		  )?                # optional.
		  		  ($ns_re)          # namespace
		  		  :
		  		  ($alias_re)       # long name
		  		  $
		 		 }xo ) {
	$name=$long unless defined $name;
	ctflags::export_sub($package, $name,
			    resolve_ctflag_alias($ns, $long))
      }
      elsif ($key eq 'package') {
	$package=shift;
	check_package $package;
      }
      else {
	die "unknow option or invalid export specification '$key'\n";
      }
    }
  };
  if ($@) { chomp $@; croak $@ };
}

1;
__END__