From 7f3d7a379017cf30439cb05bdfe1d70a9a4fb6ee Mon Sep 17 00:00:00 2001 From: Mark Nunberg Date: Tue, 24 Jan 2012 00:04:48 -0800 Subject: [PATCH] 0.15 Some minor API tweaks: added 'dualvar' option, fixed POD errors, changed ::Stringified to ::Dualvar https://rt.cpan.org/Ticket/Display.html?id=74247 https://rt.cpan.org/Ticket/Display.html?id=74249 https://rt.cpan.org/Ticket/Display.html?id=74235 --- Changes | 15 ++++-- MANIFEST | 2 + lib/Constant/Generate.pm | 79 ++++++++++++++++++---------- lib/Constant/Generate/Dualvar.pm | 56 ++++++++++++++++++++ lib/Constant/Generate/Stringified.pm | 56 ++------------------ t/99-api_revision.t | 23 ++++++++ 6 files changed, 145 insertions(+), 86 deletions(-) create mode 100644 lib/Constant/Generate/Dualvar.pm create mode 100644 t/99-api_revision.t diff --git a/Changes b/Changes index cba541e..28e1846 100644 --- a/Changes +++ b/Changes @@ -1,9 +1,14 @@ Revision history for Constant-Generate -0.01 Date/time - First version, released on an unsuspecting world. +0.15 Some minor API tweaks: + added 'dualvar' option, fixed POD errors, + changed ::Stringified to ::Dualvar + + https://rt.cpan.org/Ticket/Display.html?id=74247 + https://rt.cpan.org/Ticket/Display.html?id=74249 + https://rt.cpan.org/Ticket/Display.html?id=74235 -0.04 Updated dependency for constant.pm -0.10 Stringy options, listings -0.11 Fixed some documentation 0.12 Explained listings a bit better +0.11 Fixed some documentation +0.10 Stringy options, listings +0.04 Updated dependency for constant.pm diff --git a/MANIFEST b/MANIFEST index 73b6d9e..a8924da 100644 --- a/MANIFEST +++ b/MANIFEST @@ -4,11 +4,13 @@ Makefile.PL README lib/Constant/Generate.pm lib/Constant/Generate/Stringified.pm +lib/Constant/Generate/Dualvar.pm t/00-all.t t/01-strings.t t/02-dualvar.t t/03-listings.t t/99-synopsis.t +t/99-api_revision.t test.pl diff --git a/lib/Constant/Generate.pm b/lib/Constant/Generate.pm index b351fce..da4f432 100644 --- a/lib/Constant/Generate.pm +++ b/lib/Constant/Generate.pm @@ -1,11 +1,11 @@ package Constant::Generate; use strict; use warnings; -our $VERSION = '0.12'; +our $VERSION = '0.15'; use Data::Dumper; use Carp qw(confess); -use Constant::Generate::Stringified; +use Constant::Generate::Dualvar; use Scalar::Util qw(looks_like_number); #these two functions produce reverse mapping, one for simple constants, and @@ -186,7 +186,9 @@ sub import { my $prefix = _getopt(%opts, "prefix") || ""; my $display_prefix = _getopt(%opts, "show_prefix"); my $start = _getopt(%opts, "start_at") || 0; - my $stringy = _getopt(%opts, "stringy_vars"); + my $stringy = _getopt(%opts, "stringy_vars") + || _getopt(%opts, "dualvar"); + my $listname = _getopt(%opts, "allvalues"); my $symsname = _getopt(%opts, "allsyms"); @@ -208,7 +210,7 @@ sub import { my $dv_name = $display_prefix ? $prefix . $symname : $symname; - $symval = Constant::Generate::Stringified::CG_dualvar( + $symval = Constant::Generate::Dualvar::CG_dualvar( $symval, $dv_name); } _gen_constant($reqpkg, $prefix.$symname, $symval); @@ -269,7 +271,7 @@ Simplest use Bitflags: - use Constant::Generate [qw(ANNOYING STRONG LAZY)], type => 'bitflags'; + use Constant::Generate [qw(ANNOYING STRONG LAZY)], type => 'bits'; my $state = (ANNOYING|LAZY); $state & STRONG == 0; @@ -277,7 +279,7 @@ With reverse mapping: use Constant::Generate [qw(CLIENT_IRSSI CLIENT_XCHAT CLIENT_PURPLE)], - type => "bitflags", + type => "bits", mapname => "client_type_to_str"; my $client_type = CLIENT_IRSSI | CLIENT_PURPLE; @@ -296,19 +298,19 @@ Generate reverse maps, but do not generate values. also, push to exporter O_WRONLY => 01, O_RDWR => 02, O_CREAT => 0100 - }, tag => "openflags", -type => 'bits'; + }, tag => "openflags", type => 'bits'; my $oflags = O_RDWR|O_CREAT; print openflags_to_str($oflags); #prints 'O_RDWR|O_CREAT'; DWIM Constants - use Constant::Generate::Stringified { + use Constant::Generate { RDONLY => 00, WRONLY => 01, RDWR => 02, CREAT => 0100 - }, -prefix => 'O_'; + }, prefix => 'O_', dualvar => 1; my $oflags = O_RDWR|O_CREAT; O_RDWR eq 'RDWR'; @@ -366,7 +368,7 @@ By default, symbols are assumed to correlate to a single independent integer val and any reverse mapping performed will only ever map a symbol value to a single symbol name. -For bitflags, it is possible to specify C 'bitfield'> in the L +For bitflags, it is possible to specify C 'bits'> in the L which will modify the auto-generation of the constants as well as provide suitable output for reverse mapping functions. @@ -374,6 +376,9 @@ suitable output for reverse mapping functions. The second argument to the import function is a hash of options. +All options may be prefixed by a dash (C<-option>) or in their 'bare' form +(C