forked from mnunberg/Constant-Generate
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
6 changed files
with
145 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package Constant::Generate::Dualvar::_Overloaded; | ||
use constant { | ||
FLD_INT => 0, | ||
FLD_STR => 1 | ||
}; | ||
#Stolen from: | ||
#http://perldoc.perl.org/overload.html | ||
|
||
sub new { my $p = shift; bless [@_], $p } | ||
use overload '""' => \&str, '0+' => \&num, fallback => 1; | ||
sub num {shift->[0]} | ||
sub str {shift->[1]} | ||
|
||
|
||
BEGIN { | ||
$INC{'Constant/Generate/Dualvar/_Overloaded.pm'} = 1; | ||
} | ||
|
||
package Constant::Generate::Dualvar; | ||
use strict; | ||
use warnings; | ||
use Scalar::Util; | ||
use base qw(Exporter); | ||
|
||
our @EXPORT_OK = qw(CG_dualvar); | ||
our $USE_SCALAR_UTIL; | ||
|
||
sub CG_dualvar($$); | ||
|
||
BEGIN { | ||
$USE_SCALAR_UTIL = eval 'use List::Util::XS 1.20; $List::Util::XS::VERSION;'; | ||
if($USE_SCALAR_UTIL) { | ||
*CG_dualvar = \&Scalar::Util::dualvar; | ||
} else { | ||
require Constant::Generate::Stringified::_Overloaded; | ||
warn "Scalar::Util::XS not available. Falling back to using overload"; | ||
*CG_dualvar = sub($$) { | ||
my ($num,$string) = @_; | ||
return Constant::Generate::Stringified::_Overloaded->new( | ||
$num,$string); | ||
} | ||
} | ||
} | ||
|
||
sub import { | ||
my ($cls,$symspec,%options) = @_; | ||
if($symspec) { | ||
#We're being imported as user.. | ||
require 'Constant/Generate.pm'; | ||
$options{dualvar} = 1; | ||
@_ = ('Constant::Generate', $symspec, %options); | ||
goto &Constant::Generate::import; | ||
} else { | ||
goto &Exporter::import; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,8 @@ | ||
package Constant::Generate::Stringified::_Overloaded; | ||
use constant { | ||
FLD_INT => 0, | ||
FLD_STR => 1 | ||
}; | ||
#Stolen from: | ||
#http://perldoc.perl.org/overload.html | ||
|
||
sub new { my $p = shift; bless [@_], $p } | ||
use overload '""' => \&str, '0+' => \&num, fallback => 1; | ||
sub num {shift->[0]} | ||
sub str {shift->[1]} | ||
|
||
|
||
BEGIN { | ||
$INC{'Constant/Generate/Stringified/_Overloaded.pm'} = 1; | ||
} | ||
|
||
package Constant::Generate::Stringified; | ||
use strict; | ||
use warnings; | ||
use Scalar::Util; | ||
use base qw(Exporter); | ||
require Constant::Generate::Dualvar; | ||
|
||
our @EXPORT_OK = qw(CG_dualvar); | ||
our $USE_SCALAR_UTIL; | ||
|
||
sub CG_dualvar($$); | ||
|
||
BEGIN { | ||
$USE_SCALAR_UTIL = eval 'use List::Util::XS 1.20; $List::Util::XS::VERSION;'; | ||
if($USE_SCALAR_UTIL) { | ||
*CG_dualvar = \&Scalar::Util::dualvar; | ||
} else { | ||
require Constant::Generate::Stringified::_Overloaded; | ||
warn "Scalar::Util::XS not available. Falling back to using overload"; | ||
*CG_dualvar = sub($$) { | ||
my ($num,$string) = @_; | ||
return Constant::Generate::Stringified::_Overloaded->new( | ||
$num,$string); | ||
} | ||
} | ||
sub import { | ||
goto &Constant::Generate::Dualvar::import; | ||
} | ||
|
||
sub import { | ||
my ($cls,$symspec,%options) = @_; | ||
if($symspec) { | ||
#We're being imported as user.. | ||
require 'Constant/Generate.pm'; | ||
$options{stringy_vars} = 1; | ||
@_ = ('Constant::Generate', $symspec, %options); | ||
goto &Constant::Generate::import; | ||
} else { | ||
goto &Exporter::import; | ||
} | ||
} | ||
1; |
Oops, something went wrong.