Class-CompiledC
view release on metacpan or search on metacpan
lib/Class/CompiledC.pm view on Meta::CPAN
sub Foo : Field(Int)
Ensures that the field can only hold a valid integer value.
(beside the always legal undefined value).
=head3 Isa
sub Foo : Field(Isa(Some::Class))
Ensures that the field can only hold a reference to a object of the specified
class, or a subclass of it. (beside the always legal undefined value). (The
relationship is determined the same way as the C<UNIVERSAL->isa> method)
=head3 Number
sub Foo : Field(Number)
At current this just an alias for the C<Float> type, but that may change.
=head3 Object
sub Foo : Field(Object)
Ensures that the field can only hold a reference to a object.
(beside the always legal undefined value).
=head3 Ref
sub Foo : Field(Ref)
Ensures that the field can only hold a reference to something.
(beside the always legal undefined value).
=head3 Regexpref
sub Foo : Field(Regexpref)
Ensures that the field can only hold a reference to a regular expression object.
(beside the always legal undefined value).
=head3 String
sub Foo : Field(String)
Ensures that the field can only hold a string value. Even everything could
theoretically expressed as a string, only true string values are legal. (beside
the always legal undefined value).
=head2 Field Types Specification Syntax Note
Field types are case insensitve. If a type expects a parameter, as the C<Isa>
type, then it should be enclosed in parenthises. Whitespace is always ingnored,
around Field types and parameters, if any. Note, however that the field type
Int, spelled in lowercase letters will be misparsed as the `int` operator, so be
careful.
=head2 Additional Features
Currently there are two categories of additional features: those going to stay,
and those going to be relocated into distinct packages.
First the stuff that will stay:
=head3 parseArgs method
Every subclass inherits this method. Its purpose is to ease the use of named
parameters in constructors. It takes a list of key => value pairs. Foreach pair
it calls a method named like the key with value as it only parameter (beside the
object, of course), i.e:
$obj->parseArgs(foo => [], bar => 'bar is better than foo');
Would result in the following method calls:
$obj->foo([]);
$obj->bar('bar is better than foo');
The method also strips a leading dash ('-') from the method name, in case you
prefer named arguments starting with a dash, therefore the following calls are
equivalent :
$obj->parseArgs(-foo => 123, -bar => 456); # dashed style
$obj->parseArgs(foo => 123, bar => 456); # dashless style
$obj->parseArgs(-foo => 123, bar => 456); # no style
Since this method needs key => value pairs it will croak if you supply it an odd
number of arguments. I<actually it croaks on an even number of arguments, if you
also count the object. but the check for oddnes is done after the object is
shifted from the argument list>
C<parseArgs> returns the object.
=head3 new method
Every subclass inherits this method, it is merely a wrapper around the real
constructor (which is called 'create'). It first constructs the object (with the
help of the real constructor) and then calls parseArgs on it. This means the
following code is equivalent :
my $obj = class->new(-foo => 'bar');
#----
my $obj = class->create;
$obj->parseArgs(-foo => 'bar');
Only shorter ;)
=head3 inspect method
This method is created for each subclass. It returns a hashref with the field
names and their types. A short example should clarify what I try to say:
package SomeClass;
use base qw/Class::CompiledC/;
sub foo : Field(Int);
sub bar : Filed(Hashref);
lib/Class/CompiledC.pm view on Meta::CPAN
=over
=item *serious code cleanup
I still find too much things that are done the fast way instead of the right
way, this really bothers me.
=item *outsourcing
A few things need to be outsourced right away. I just don't know where to put
them. Especially the stuff not related to classes should be placed somewhere
else. The utility __.* subs (not methods!) could be placed in a different
package and locally (or maybe lexically?) imported, to avoid namespace pollution
of subclasses.
Random thought: lexical importing ? what a cute idea! is this possible?
=back
=head1 SEE ALSO
=over
=item TODO
=back
=head1 AUTHOR
blackhat.blade
The Hive
blade@focusline.de
=head1 COPYRIGHT
Copyright (c) 2005, 2006
blackhat.blade The Hive. All Rights Reserved.
This module is free software. It may be used, redistributed
and/or modified under the terms of the Artistic license.
=cut
1;
__END__
2.14 Wed Jan 18 00:44:39 CET 2006 @31 /Internet Time/
everything till here...
2.15 Thu Jan 19 20:28:41 CET 2006 @853 /Internet Time/
fixed documentation issues, the Field type for regular exprssions
is C<Regexpref> and I<not> C<Regexref>. I also had Regexenref in mind...
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.
2.21 Fri Oct 27 23:27:38 CEST 2006 @935 /Internet Time/
no code changes, fixed errors in Makefile.pl
2.22 Sun Oct 29 22:52:42 CET 2006 @953 /Internet Time/
updated documentation,
minor code cleanups.
( run in 2.543 seconds using v1.01-cache-2.11-cpan-71847e10f99 )