Class-CompiledC
view release on metacpan or search on metacpan
lib/Class/CompiledC.pm view on Meta::CPAN
our $re_ft;
our $re_ft_isa;
sub __circumPrint($$$);
sub __include;
sub __baseref($$);
sub __hashref($);
sub __arrayref($);
sub __coderef($);
sub __fetchSymbolName($);
sub __promoteFieldTypeToMacro($);
sub __parseFieldType;
$re_ft = qr/^(?:\s*)(int|float|number|string|ref|arrayref|hashref|
coderef|object|regexpref|any|uint)(?:\s*)/xi;
$re_ft_isa = qr/^(?:\s*)isa(?:\s*)\((?:\s*)([\w:]*)(?:\s*)\)(?:\s*)/i;
=head1 ABSTRACT
lib/Class/CompiledC.pm view on Meta::CPAN
sub __fetchSymbolName($)
{
no strict 'refs';
my $symbol = shift;
__baseref $symbol, 'GLOB' or croak 'not a GLOB reference';
return *$symbol{NAME};
}
=head3 __promoteFieldTypeToMacro
__promoteFieldTypeToMacro FIELDTYPE
Type: Subroutine.
Export: on request.
Prototype: none
Takes a fieldtype specfication, and returns a C<C> macro for doing the test.
Does not handle parametric types like C<isa>. See C<__parseFieldType> for that.
=cut
sub __promoteFieldTypeToMacro($)
{
my $type = shift;
return '' unless ($type);
return '' if ($type =~ /^any$/i);
return sprintf '__CHECK(__IS%s(__ARG0), "%s")', uc $type, $type;
}
=head3 __parseFieldType
__parseFieldType FIELDTYPE
Type: Subroutine.
Export: on request.
Prototype: none
Takes a fieldtype specfication, and returns a C<C> macro for doing the test.
Handles all field types. Delegates most work to the C<__promoteFieldTypeToMacro>
subroutine.
=cut
sub __parseFieldType
{
local $_ = shift;
if (/$re_ft/)
{
# warn sprintf "yeah %s !", __promoteFieldTypeToMacro $1;
return __promoteFieldTypeToMacro($1);
}
elsif (/$re_ft_isa/)
{
croak "fail0r: isa type needs a classname argument\n" unless $1;
return '__CHECK(__ISA(__ARG0, '."\"$1\"), \"__ISA\")";
}
else
{
croak "fail0r: bad type specified $_\n";
lib/Class/CompiledC.pm view on Meta::CPAN
=item all Everything.
=back
=cut
BEGIN
{
$EXPORT_TAGS{ref} = [qw/__arrayref __coderef __hashref/];
$EXPORT_TAGS{misc} = [qw/__fetchSymbolName __baseref __circumPrint/];
$EXPORT_TAGS{field} = [qw/__parseFieldType __promoteFieldTypeToMacro/];
$EXPORT_TAGS{intern} = [qw/__include/];
$EXPORT_TAGS{all} = [map {@{$_}} values %EXPORT_TAGS ];
}
=head2 Exportable Symbols
The following subroutines are (im|ex)portable, either explicitly by name or
as part of a tag.
=over
lib/Class/CompiledC.pm view on Meta::CPAN
=item C<__hashref>
=item C<__fetchSymbolName>
=item C<__baseref>
=item C<__circumPrint>
=item C<__parseFieldType>
=item C<__promoteFieldTypeToMacro>
=back
=cut
BEGIN
{
@EXPORT_OK = @{$EXPORT_TAGS{all}};
}
lib/Class/CompiledC.pm view on Meta::CPAN
2.16 Sun Oct 08 00:05:19 CEST 2006 @962 /Internet Time/
fixed (?:Array|Code|Hash)ref type checking code
2.17 Sat Oct 21 01:01:45 CEST 2006 @1 /Internet Time/
added a few sanity checks for __fetchSymbolName
2.18 Sun Oct 22 13:21:16 CEST 2006 @514 /Internet Time/
fixed some serious bugs concerning refcounts of non ref values
fixed (?:Array|Code|Hash)ref type checking code
2.19 Sun Oct 22 19:52:04 CEST 2006 @786 /Internet Time/
relocated field type parsing into __genBaseCode in anticipation to support
introspection
refactored __promoteFieldTypeToMacro sub
adapted __addParentFields to emit only valid field types
added inspect method, it returns a hashref with fieldnames as keys and
field types as values. (you may change that hash but don't expect any
changes to persist, or even to propagate back and change the class on the
fly, we are not at this point, and we're not going into this directon)
2.20 Thu Oct 26 21:48:22 CEST 2006 @866 /Internet Time/
first public release
renamed to Class::CompiledC to avoid the creation of a new root namespace
added version requirement for 5.8.7, sorry for this but I cannot tell if
it will run with earlier versions.
t/Class-CompiledC.t view on Meta::CPAN
dies_with
{
Class::CompiledC::__fetchSymbolName(qr/foo/),
} qr/not a glob reference/i, '__fetchSymbolName negative (regexref)';
dies_with
{
Class::CompiledC::__fetchSymbolName(bless [], 'foobar'),
} qr/not a glob reference/i, '__fetchSymbolName negative (blessed reference)';
is (Class::CompiledC::__promoteFieldTypeToMacro('FOO'),
'__CHECK(__ISFOO(__ARG0), "FOO")',
'__promoteFieldTypeToMacro simple test');
is (Class::CompiledC::__promoteFieldTypeToMacro('fOoBaR'),
'__CHECK(__ISFOOBAR(__ARG0), "fOoBaR")',
'__promoteFieldTypeToMacro case test');
is (Class::CompiledC::__promoteFieldTypeToMacro('any'),
'',
'__promoteFieldTypeToMacro any test');
is (Class::CompiledC::__parseFieldType('Isa(FOO)'),
'__CHECK(__ISA(__ARG0, "FOO"), "__ISA")',
'__parseFieldType isa test');
is (Class::CompiledC::__parseFieldType('int'),
'__CHECK(__ISINT(__ARG0), "int")',
'__parseFieldType int test');
is (Class::CompiledC::__parseFieldType('float'),
( run in 0.527 second using v1.01-cache-2.11-cpan-49f99fa48dc )