Aspect
view release on metacpan or search on metacpan
lib/Aspect.pm view on Meta::CPAN
$automobile = Automobile->new;
$van = Van->new;
$automobile->compute_mileage; # Automobile!
$van->compute_mileage; # Automobile!, should also print Van!
C<Van!> will never be printed. This happens because B<Aspect> installs
advice code on symbol table entries. C<Van::compute_mileage> does not
have one, so nothing happens. Until this is solved, you have to do the
thinking about inheritance yourself.
=head2 Performance
You may find it very easy to shoot yourself in the foot with this module.
Consider this advice:
# Do not do this!
before {
print $_->sub_name;
} cflow 'MyApp::Company::make_report';
The advice code will be installed on B<every> sub loaded. The advice code
will only run when in the specified call flow, which is the correct
behavior, but it will be I<installed> on every sub in the system. This
can be extremely slow because the run-time cost of checking C<cflow> will
occur on every single function called in your program.
It happens because the C<cflow> pointcut matches I<all> subs during weave-time.
It matches the correct sub during run-time. The solution is to narrow the
pointcut:
# Much better
before {
print $_->sub_name;
} call qr/^MyApp::/
& cflow 'MyApp::Company::make_report';
=head1 TO DO
There are a many things that could be added, if people have an interest
in contributing to the project.
=head2 Documentation
* cookbook
* tutorial
* example of refactoring a useful CPAN module using aspects
=head2 Pointcuts
* New pointcuts: execution, cflowbelow, within, advice, calledby. Sure
you can implement them today with Perl treachery, but it is too much
work.
* We need a way to match subs with an attribute, attributes::get()
will currently not work.
* isa() support for method pointcuts as Gaal Yahas suggested: match
methods on class hierarchies without callbacks
* Perl join points: phasic- BEGIN/INIT/CHECK/END
=head2 Weaving
* The current optimation has gone as far as it can, next we need to look into
XS acceleration and byte code manipulation with B:: modules.
* A debug flag to print out subs that were matched during weaving
* Warnings when over 1000 methods wrapped
* Allow finer control of advice execution order
* Centralised hooking in wrappers so that each successive advice won't need
to wrap around the previous one.
* Allow lexical aspects to be safely removed completely, rather than being left
in place and disabled as in the current implementation.
=head1 SUPPORT
Please report any bugs or feature requests through the web interface at
L<http://rt.cpan.org/Public/Dist/Display.html?Name=Aspect>.
=head1 INSTALLATION
See L<perlmodinstall> for information and options on installing Perl modules.
=head1 AVAILABILITY
The latest version of this module is available from the Comprehensive Perl
Archive Network (CPAN). Visit <http://www.perl.com/CPAN/> to find a CPAN
site near you. Or see L<http://search.cpan.org/perldoc?Aspect>.
=head1 AUTHORS
Adam Kennedy E<lt>adamk@cpan.orgE<gt>
Marcel GrE<uuml>nauer E<lt>marcel@cpan.orgE<gt>
Ran Eilam E<lt>eilara@cpan.orgE<gt>
=head1 SEE ALSO
You can find AOP examples in the C<examples/> directory of the
distribution.
L<Aspect::Library::Memoize>
L<Aspect::Library::Profiler>
L<Aspect::Library::Trace>
=head1 COPYRIGHT
Copyright 2001 by Marcel GrE<uuml>nauer
Some parts copyright 2009 - 2013 Adam Kennedy.
( run in 0.511 second using v1.01-cache-2.11-cpan-39bf76dae61 )