.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.22)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.ie \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.el \{\
. de IX
..
.\}
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "Class::Trait 3pm"
.TH Class::Trait 3pm "2013-09-24" "perl v5.14.2" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Class::Trait \- Deprecated. Please use Moose::Role.
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 3
\& # to turn on debugging (do this before
\& # any other traits are loaded)
\& use Class::Trait \*(Aqdebug\*(Aq;
\&
\& # nothing happens, but the module is loaded
\& use Class::Trait;
\&
\& # loads these two traits and flatten them
\& # into the current package
\& use Class::Trait qw(TPrintable TComparable);
\&
\& # loading a trait and performing some
\& # trait operations (alias, exclude) first
\& use Class::Trait (
\& \*(AqTPrintable\*(Aq => {
\& alias => { "stringValue" => "strVal" },
\& exclude => "stringValue",
\& },
\& );
\&
\& # loading two traits and performing
\& # a trait operation (exclude) on one
\& # module to avoid method conflicts
\& use Class::Trait
\& \*(AqTComparable\*(Aq => {
\& # exclude the basic equality method
\& # from TComparable and use the ones
\& # in TEquality instead.
\& exclude => [ "notEqualTo", "equalTo" ]
\& },
\& \*(AqTEquality\*(Aq # <\- use equalTo and notEqualTo from here
\& );
\&
\& # when building a trait, you need it
\& # to inherit from the trait meta/base\-class
\& # so do this ...
\& use Class::Trait \*(Aqbase\*(Aq;
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This document attempts to explain Traits in terms of Perl.
.SS "Trait composition"
.IX Subsection "Trait composition"
A Trait can be defined as a package containing:
.IP "\(bu" 4
A set of methods
.IP "\(bu" 4
A hash of overloaded operators mapped to the method labels
.IP "\(bu" 4
An array of required method labels
.PP
Here is an example of the syntax for a very basic trait:
.PP
.Vb 1
\& package TPrintable;
\&
\& use Class::Trait \*(Aqbase\*(Aq;
\&
\& our @REQUIRES = qw(toString);
\&
\& our %OVERLOADS = (\*(Aq""\*(Aq => toString);
\&
\& sub stringValue {
\& my ($self) = @_;
\& require overload;
\& return overload::StrVal($self);
\& }
\&
\& 1;
.Ve
.PP
The above example requires the user of the trait to implement a \f(CW\*(C`toString\*(C'\fR
method, which the overloaded \f(CW""\fR operator then utilizes. The trait also
provides a \f(CW\*(C`stringValue\*(C'\fR method to the consuming class.
.SS "Trait usage"
.IX Subsection "Trait usage"
When a class uses a Trait:
.IP "\(bu" 4
Requirements
.Sp
All requirements of the traits (or composite trait) must be meet either by the
class itself or by one of its base classes.
.IP "\(bu" 4
Flattening
.Sp
All the non-conflicting trait (or composite trait) methods are flattened into
the class, meaning an entry is created directly in the class's symbol table
and aliased to the original trait method. Only methods defined in the trait
are used. Subroutines imported into the trait are not used.
.IP "\(bu" 4
Conflicts
.Sp
If a method label in a class conflicts with a method label in the trait (or
composite trait), the class method is chosen and the trait method is
discarded. This only applies to methods defined directly in the class's symbol
table, methods inherited from a base class are overridden by the trait method.
.PP
Here is a simple example of the usage of the above trait in a class.
.PP
.Vb 1
\& package MyClass;
\&
\& use Class::Trait (
\& \*(AqTPrintable\*(Aq => {
\& alias => { "strVal" => "stringValue" }
\& exclude => "stringValue",
\& }
\& );
\&
\& sub stringValue { ... }
.Ve
.PP
The above example would use the \f(CW\*(C`TPrintable\*(C'\fR trait, aliasing \f(CW\*(C`stringValue\*(C'\fR
to the method label \f(CW\*(C`strVal\*(C'\fR, and then excluding \f(CW\*(C`stringValue\*(C'\fR. This is done
to avoid a conflict with \f(CW\*(C`stringValue\*(C'\fR method implemented in the class that
uses the trait.
.SS "Trait operations"
.IX Subsection "Trait operations"
When using a trait, the class can make changes to the structure of a trait
through the following methods.
.IP "\(bu" 4
Exclusion
.Sp
An array of method labels to exclude from trait. If only a single method
needs to be excluded, you may provide the method name without an array.
.IP "\(bu" 4
Alias
.Sp
A hash of old method labels to new method labels.
.IP "\(bu" 4
Summation
.Sp
A number of traits can be combined into one.
.PP
\fIExclusion\fR
.IX Subsection "Exclusion"
.PP
This excludes a method from inclusion in the class which is using the trait.
It does however cause the method to be added to the traits required methods.
This is done because it is possible that other methods within the trait rely
on the excluded method, and therefore it must be implemented somewhere in
order for the other method to work.
.PP
\fIAliasing\fR
.IX Subsection "Aliasing"
.PP
Aliasing is not renaming or redefining, it does not remove the old method, but
instead just introduces another label for that method. The old method label
can be overridden or excluded without affecting the new method label.
.PP
One special note is that aliasing does move any entry in the overloaded
operators to use the new method name, rather than the old method name. This is
done since many times aliasing is used in conjunction with exclusion to
pre-resolve conflicts. This avoids the orphaning of the operator.
.PP
\fISummation\fR
.IX Subsection "Summation"
.PP
When two or more traits are used by a class (or another trait), the traits are
first compiled into a composite trait. The resulting composite trait is:
.IP "\(bu" 4
Methods
.Sp
A union of all non-conflicting methods of all traits.
.IP "\(bu" 4
Operators
.Sp
A union of all non-conflicting operators of all traits.
.IP "\(bu" 4
Requirements
.Sp
A union of all unsatisfied requirements of all traits.
.PP
Method conflicts
.IX Subsection "Method conflicts"
.PP
Method equality if determined by two conditions, the first being method label
string equality, the second being the hex address of the code reference (found
by stringifying the subroutine reference).
.PP
If a method in one of the traits is deemed to be in conflict with a method in
another trait, the result is the exclusion of that method from the composite
trait. The method label is then added to the requirements array for the
composite trait.
.PP
Method conflict can be avoided by using exclusion or a combination of aliasing
and exclusion.
.PP
Operator conflicts
.IX Subsection "Operator conflicts"
.PP
Operator conflicts also result in the exclusion of the operator from the
composite trait and the operator then becomes a requirement.
.PP
Requirement satisfaction
.IX Subsection "Requirement satisfaction"
.PP
One trait may satisfy the requirements of another trait when they are combined
into a composite trait. This results in the removal of the requirement from
the requirements array in the composite trait.
.SH "RUNTIME TRAIT APPLICATION"
.IX Header "RUNTIME TRAIT APPLICATION"
As of \f(CW\*(C`Class::Trait\*(C'\fR version 0.20, you can now apply traits at runtime to
both classes and instances by using the \f(CW\*(C`apply()\*(C'\fR method. Applying a trait
at runtime is similar to using the trait as a mixin because existing methods
will be overwritten.
.PP
The syntax is:
.PP
.Vb 1
\& Class::Trait\->apply($class_or_instance, @list_of_traits);
.Ve
.SS "Classes"
.IX Subsection "Classes"
Applying a trait at runtime to a class:
.PP
.Vb 7
\& if ($secure) {
\& Class::Trait\->apply($class_name, \*(AqTSecureConnection\*(Aq);
\& }
\& else {
\& warn "Using insecure connections";
\& Class::Trait\->apply($class_name, \*(AqTInsecureConnection\*(Aq);
\& }
.Ve
.PP
Now all instances of \f(CW$class_name\fR will have the methods provided by the
trait applied. If the trait applied at runtime provides methods already
defined in \f(CW$class_name\fR, the \f(CW$class_name\fR methods will be silently
redefined with the trait's methods.
.SS "Instances"
.IX Subsection "Instances"
Applying a trait at runtime to an instance:
.PP
.Vb 7
\& if ($secure) {
\& Class::Trait\->apply($instance, \*(AqTSecureConnection\*(Aq);
\& }
\& else {
\& warn "Using insecure connections";
\& Class::Trait\->apply($instance, \*(AqTInsecureConnection\*(Aq);
\& }
.Ve
.PP
When applying a trait (or set of traits) to an instance of a class, \fBonly\fR
that instance gets the new methods. If you want numerous instances to receive
the new methods, either apply the trait to all instances or consider applying
it to the class.
.PP
Note that the instance is blessed into a new, anonymous class and it's this
class which contains the new methods.
.SH "WHEN TO USE TRAITS"
.IX Header "WHEN TO USE TRAITS"
For a relatively simple class heirarchy you may need traits. There are,
however, several key indicators that traits may be beneficial for you.
.IP "\(bu" 4
Duplicated behavior
.Sp
Whenever you've duplicated behavior across unrelated classes.
.IP "\(bu" 4
Multiple inheritance
.Sp
Any time you might think about \s-1MI\s0 and it's only for code reuse (in other
words, the subclass is not a more specific type of a super class)
.IP "\(bu" 4
Interfaces
.Sp
Any time you might want a Java-style interface but you also want an
implementation to go with that.
.IP "\(bu" 4
Mixins
.Sp
Any time you might want to use mixins (have you ever considered exporting
methods?)
.SH "EXPORTS"
.IX Header "EXPORTS"
.IP "\(bu" 4
\&\fB\f(CB$TRAITS\fB\fR
.Sp
While not really exported, Class::Trait leaves the actual Class::Trait::Config
object applied to the package stored as scalar in the package variable at
\&\f(CW$TRAITS\fR.
.IP "\(bu" 4
\&\fBdoes\fR
.Sp
Class::Trait will export this method into any object which uses traits. By
calling this method you can query the kind of traits the object has
implemented. The method works much like the perl \f(CW\*(C`isa\*(C'\fR method in that it
performs a depth-first search of the traits hierarchy and returns true (1) if
the object implements the trait, and false (0) otherwise.
.Sp
.Vb 1
\& $my_object_with_traits\->does(\*(AqTPrintable\*(Aq);
.Ve
.Sp
Calling \f(CW\*(C`does\*(C'\fR without arguments will return all traits an ojbect does.
.IP "\(bu" 4
\&\fBis\fR
.Sp
Class::Trait used to export this method to any object which uses traits, but
it was found to conflict with Test::More::is. The recommended way is to use
\&\f(CW\*(C`does\*(C'\fR.
.Sp
To use \f(CW\*(C`is\*(C'\fR instead of \f(CW\*(C`does\*(C'\fR, one trait must use the following syntax for
inheritance:
.Sp
.Vb 1
\& use Class::Trait qw/base is/;
.Ve
.Sp
Instead of:
.Sp
.Vb 1
\& use Class::Trait \*(Aqbase\*(Aq;
.Ve
.Sp
It is recommended that all traits use this syntax if necessary as the
mysterious \*(L"action at a distance\*(R" of renaming this method can be confusing.
.Sp
As an alternative, you can also simply use the following in any code which
uses traits:
.Sp
.Vb 4
\& BEGIN {
\& require Class::Trait;
\& Class::Trait\->rename_does(\*(Aqis\*(Aq);
\& }
.Ve
.Sp
This is generally not recommended in test suites as \fITest::More::is()\fR conflicts
with this method.
.SH "METHODS"
.IX Header "METHODS"
.IP "\fBinitialize\fR" 4
.IX Item "initialize"
Class::Trait uses the \s-1INIT\s0 phase of the perl compiler, which will not run
under mod_perl or if a package is loaded at runtime with \f(CW\*(C`require\*(C'\fR. In order
to insure that all traits a properly verified, this method must be called.
However, you may still use Class::Trait without doing this, for more details
see the \s-1CAVEAT\s0 section.
.IP "\fBrename_does\fR" 4
.IX Item "rename_does"
Note: You probably do not want to use this method.
.Sp
Class::Trait uses \f(CW\*(C`does()\*(C'\fR to determine if a class can \*(L"do\*(R" a particular
trait. However, your package may already have a \f(CW\*(C`does()\*(C'\fR method defined or
you may be migrating from an older version of Class::Trait which uses
\&\f(CW\*(C`is()\*(C'\fR to perform this function. To rename \f(CW\*(C`does()\*(C'\fR to something more
suitable, you can use this at the top of your code:
.Sp
.Vb 4
\& BEGIN {
\& require Class::Trait; # we do not want to call import()
\& Class::Trait\->rename_does($some_other_method_name);
\& }
\&
\& use Class::Trait \*(Aqsome_trait\*(Aq;
.Ve
.Sp
If you wish to shield your users from seeing this, you can declare any trait
with:
.Sp
.Vb 1
\& use Class::Trait qw/base performs/; # \*(Aqperforms\*(Aq can be any valid method name
.Ve
.Sp
You only need to do that in one trait and all traits will pick up the new
method name.
.SH "TRAIT LIBRARY"
.IX Header "TRAIT LIBRARY"
I have moved some of the traits in the test suite to be used outside of this,
and put them in what I am calling the trait library. This trait library will
hopefully become a rich set of base level traits to use when composing your
own traits. Currently there are the following pre-defined traits.
.IP "\(bu" 4
TPrintable
.IP "\(bu" 4
TEquality
.IP "\(bu" 4
TComparable
.PP
These can be loaded as normal traits would be loaded, Class::Trait will know
where to find them. For more information about them, see their own
documenation.
.SH "DEBUGGING"
.IX Header "DEBUGGING"
Class::Trait is really an experimental module. It is not ready yet to be used
seriously in production systems. That said, about half of the code in this
module is dedicated to formatting and printing out debug statements to \s-1STDERR\s0
when the debug flag is turned on.
.PP
.Vb 1
\& use Class::Trait \*(Aqdebug\*(Aq;
.Ve
.PP
The debug statements prints out pretty much every action taken during the
traits compilation process and on occasion dump out \fBData::Dumper\fR output of
trait structures. If you are at all interested in traits or in this module, I
recommend doing this, it will give you lots of insight as to what is going on
behind the scences.
.SH "CAVEAT"
.IX Header "CAVEAT"
This module uses the \s-1INIT\s0 phase of the perl compiler to do a final check of
the of the traits. Mostly it checkes that the traits requirements are fufilled
and that your class is safe to use. This presents a problem in two specific
cases.
.IP "\fBUnder mod_perl\fR" 5
.IX Item "Under mod_perl"
mod_perl loads \fBall\fR code through some form of eval. It does this \fIafter\fR
the normal compilation phases are complete. This means we cannot run \s-1INIT\s0.
.IP "\fBRuntime loading\fR" 5
.IX Item "Runtime loading"
If you load code with \f(CW\*(C`require\*(C'\fR or \f(CW\*(C`eval "use Module"\*(C'\fR the result is the
same as with mod_perl. It is post-compilation, and the \s-1INIT\s0 phase cannot be
run.
.PP
However, this does not mean you cannot use Class::Trait in these two
scenarios. Class::Trait will just not check its requirements, these routines
will simply throw an error if called.
.PP
The best way to avoid this is to call the class method \f(CW\*(C`initialize\*(C'\fR, after
you have loaded all your classes which utilize traits, or after you
specifically load a class with traits at runtime.
.PP
.Vb 1
\& Class::Trait\->initialize();
.Ve
.PP
This will result in the final checking over of your classes and traits, and
throw an exception if there is a problem.
.PP
Some people may not object to this not-so-strict behavior, the smalltalk
implementation of traits, written by the authors of the original papers
behaves in a similar way. Here is a quote from a discussion I had with
Nathanael Scharli, about the Smalltalk versions behavior:
.PP
.Vb 9
\& Well, in Squeak (as in the other Smalltalk dialects), the difference
\& between runtime and compile time is not as clear as in most other
\& programming languages. The reason for this is that programming in
\& Smalltalk is very interactive and there is no explicit compile phase.
\& This means that whenever a Smalltalk programmer adds or modifies a method,
\& it gets immediately (and automatically) compiled and installed in the
\& class. (Since Smalltalk is not statically typed, there are no type checks
\& performed at compile time, and this is why compiling a method simply means
\& creating and installing the byte\-code of that method).
\&
\& However, I actually like if the programmer gets as much static information
\& bout the code as possible. Therefore, my implementation automaticelly
\& checks the open requirements whenever a method gets
\& added/removed/modified. This means that in my implementation, the
\& programmer gets interactive feedback about which requirements are still to
\& be satisfied while he is composing the traits together. In particular, I
\& also indicate when all the requirements of a class/trait are fulfilled. In
\& case of classes, this means for the programmer that it is now possible to
\& actually use the class without running into open requirements.
\&
\& However, according to the Smalltalk tradition, I do not prevent a
\& programmer from instantiating a class that still has open requirements.
\& (This can be useful if a programmer wants to test a certain functionality
\& of a class before it is actually complete). Of course, there is then
\& always the risk that there will be a runtime error because of an
\& unsatisfied requirement.
\&
\& As a summary, I would say that my implementation of traits keeps track of
\& the requirements at compile time. However, if an incomplete class (i.e., a
\& class with open requirements) is instantiated, unfulfilled requirements
\& result in a runtime error when they are called.
.Ve
.SH "TO DO"
.IX Header "TO DO"
I consider this implementation of Traits to be pretty much feature complete in
terms of the description found in the papers. Of course improvements can
always be made, below is a list of items on my to do list:
.IP "\fBTests\fR" 4
.IX Item "Tests"
I have revamped the test suite alot this time around. But it could always use
more. Currently we have 158 tests in the suite. I ran it through Devel::Cover
and found that the coverage is pretty good, but can use some help:
.Sp
.Vb 7
\& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\-
\& File stmt branch cond sub pod time total
\& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\-
\& /Class/Trait.pm 91.4 58.6 50.0 95.7 6.2 8.9 80.0
\& /Class/Trait/Base.pm 90.5 50.0 n/a 100.0 n/a 0.1 83.9
\& /Class/Trait/Config.pm 100.0 n/a n/a 100.0 100.0 2.9 100.0
\& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\-
.Ve
.Sp
Obviously Class::Trait::Config is fine.
.Sp
To start with Class::Trait::Reflection is not even tested at all. I am not
totally happy with this \s-1API\s0 yet, so I am avoiding doing this for now.
.Sp
The pod coverage is really low in Class::Trait since virtually none of the
methods are documented (as they are not public and have no need to be
documented). The branch coverage is low too because of all the debug
statements that are not getting execute (since we do not have \s-1DEBUG\s0 on).
.Sp
The branch coverage in Class::Trait::Base is somwhat difficult. Those are
mostly rare error conditions and edge cases, none the less I would still like
to test them.
.Sp
Mostly what remains that I would like to test is the error cases. I need to
test that Class::Traits blows up in the places I expect it to.
.IP "\fBImprove mod_perl/INIT phase solution\fR" 4
.IX Item "Improve mod_perl/INIT phase solution"
Currently the work around for the mod_perl/INIT phase issue (see \s-1CAVEAT\s0) is
to just let the unfufilled requirement routines fail normally with perl. Maybe
I am a control freak, but I would like to be able to make these unfufilled
methods throw my own exceptions instead. My solution was to make a bunch of
stub routines for all the requirements. The problem is that I get a bunch of
\&\*(L"subroutine redeined\*(R" warnings coming up when the local method definitions are
installed by perl normally.
.Sp
Also, since we are installing our methods and our overloads into the class in
the \s-1BEGIN\s0 phase now, it is possible that we will get subroutine redefinition
errors if there is a local implementation of a method or operator. This is
somewhat rare, so I am not as concerned about that now.
.Sp
Ideally I would like to find a way around the \s-1INIT\s0 issue, which will still
have the elegance of using \s-1INIT\s0.
.IP "\fBReflection \s-1API\s0\fR" 4
.IX Item "Reflection API"
The class Class::Traits::Reflection gives a basic \s-1API\s0 to access to the traits
used by a class. Improvements can be made to this \s-1API\s0 as well as the
information it supplies.
.IP "\fBTools\fR" 4
.IX Item "Tools"
Being a relatively new concept, Traits can be difficult to digest and
understand. The original papers does a pretty good job, but even they stress
the usefulness of tools to help in the development and understanding of
Traits. The 'debug' setting of Class::Trait gives a glut of information on
every step of the process, but is only useful to a point. A Traits 'browser'
is something I have been toying with, both as a command line tool and a Tk
based tool.
.IP "\fBTrait Lib\fR" 4
.IX Item "Trait Lib"
In this release I have added some pre-built traits that can be used;
TEquality, TComparable, TPrintable. I want to make more of these, it will only
help.
.SH "PRIVATE METHODS IN TRAITS"
.IX Header "PRIVATE METHODS IN TRAITS"
Sometimes a trait will want to define private methods that only it can see.
Any subroutine imported into the trait from outside of the trait will
automatically be excluded. However, a trait can define private methods by
using anonymous subroutines.
.PP
.Vb 2
\& package TSomeTrait;
\& use Class::Trait \*(Aqbase\*(Aq;
\&
\& my $private = sub { ... };
\&
\& sub public {
\& my $self = shift;
\& my $data = $self\->$private;
\& ...
\& }
.Ve
.SH "ACKNOWLEDGEMENTS"
.IX Header "ACKNOWLEDGEMENTS"
.IP "\(bu" 4
Curtis \*(L"Ovid\*(R" Poe
.Sp
Initial idea and code for this module.
.IP "\(bu" 4
Nathanael Scharli and the Traits research group.
.Sp
Answering some of my questions.
.IP "\(bu" 4
Yuval Kogman
.Sp
Spotting the problem with loading traits with :: in them. Thanks to Curtis
\&\*(L"Ovid\*(R" Poe for bringing it up again, and prompting me to release the fix.
.IP "\(bu" 4
Roman Daniel
.Sp
Fixing \s-1SUPER::\s0 handling.
.IP "\(bu" 4
Curtis \*(L"Ovid\*(R" Poe
.Sp
The code to change \f(CW\*(C`is\*(C'\fR to \f(CW\*(C`does\*(C'\fR.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Class::Trait is an implementation of Traits as described in the the documents
found on this site . In
particular the paper \*(L"Traits \- A Formal Model\*(R", as well as another paper on
statically-typed traits (which is found here :
http://www.cs.uchicago.edu/research/publications/techreports/TR\-2003\-13 ).
.SH "ERROR MESSAGES"
.IX Header "ERROR MESSAGES"
.SS "Redefined subroutine warnings"
.IX Subsection "Redefined subroutine warnings"
If a class using a trait has a method which the trait defines, the class's
method is assumed to be the correct method. However, you should get a
\&\*(L"Subroutine redefined\*(R" warning. To avoid this, explicitly exclude the method:
.PP
.Vb 1
\& use Class::Trait TSomeTrait => { exclude => \*(Aqfoo\*(Aq };
\&
\& sub foo {}
.Ve
.PP
Sometimes you will see strange warnings such as:
.PP
.Vb 1
\& Subroutine Circle::(== redefined at /usr/lib/perl5/5.8.7/overload.pm at ...
.Ve
.PP
This is because traits can support overloading. To avoid this warning, define
your overloaded methods prior to using Class::Trait.
.PP
.Vb 1
\& use overload ( \*(Aq==\*(Aq => \e&equalTo );
\&
\& use Class::Trait
\& "TCircle" => { exclude => \*(AqequalTo\*(Aq },
\& "TColor" => { exclude => \*(AqequalTo\*(Aq };
.Ve
.SH "BUGS"
.IX Header "BUGS"
.SS "does"
.IX Subsection "does"
When applying traits at runtime to instances, the following works:
.PP
.Vb 1
\& $object\->does($some_trait_name);
.Ve
.PP
However, normally we should be able to do the following and get a list of all
traits the instance does:
.PP
.Vb 1
\& my @does = $object\->does;
.Ve
.PP
Currently, this returns no traits. It will be fixed in a future release.
.SH "MAINTAINER"
.IX Header "MAINTAINER"
Curtis \*(L"Ovid\*(R" Poe, \f(CW\*(C`\*(C'\fR
.SH "AUTHOR"
.IX Header "AUTHOR"
stevan little,
.PP
The development of this module was initially begun by Curtis \*(L"Ovid\*(R" Poe,
.
.SH "COPYRIGHT AND LICENSE"
.IX Header "COPYRIGHT AND LICENSE"
Copyright 2004, 2005 by Infinity Interactive, Inc.
.PP
.PP
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.