https://github.com/dnmfarrell/sub-attributes
Meta programming with subroutine attributes
https://github.com/dnmfarrell/sub-attributes
Last synced: about 2 months ago
JSON representation
Meta programming with subroutine attributes
- Host: GitHub
- URL: https://github.com/dnmfarrell/sub-attributes
- Owner: dnmfarrell
- License: other
- Created: 2016-06-21T00:23:12.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-06-30T03:25:50.000Z (almost 10 years ago)
- Last Synced: 2025-01-16T16:49:27.349Z (over 1 year ago)
- Language: Perl
- Homepage: https://metacpan.org/pod/Sub::Attributes
- Size: 11.7 KB
- Stars: 1
- Watchers: 4
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.pod
- License: LICENSE
Awesome Lists containing this project
README
=head1 NAME
Sub::Attributes - meta programming with subroutine attributes
=head1 SYNOPSIS
package Point;
use base 'Sub::Attributes';
# croak if not called as a class method
sub new :ClassMethod {
...
}
# croak if not called as object method
sub add : Method {
...
}
# private subroutine, will croak unless called from within Point package
sub _internal_logic : Private Method {
...
}
# Typical method modifiers ala LISP & Class::Method::Modifiers
# before, after & around all occur at compile time
sub check_state : Before(add) {
...
}
sub doubleme : After(add) {
...
}
# orig is a coderef to add, it needs to be given $self becase it's an object
# method
sub filter_calls : Around(add) {
my ($orig, $self, @args) = @_;
my $result = $orig->($self, @args);
...
}
package main;
my $p = Point->new(3,8);
$p->sub_attributes(); # { add => ['Method'], _internal_logic => ['Private','Method'], ... }
=head1 METHODS
=head2 sub_attributes
Returns a hashref of subroutine names and their attributes.
=head1 SEE ALSO
=over 4
=item * L
=item * L
=back
=head1 AUTHOR
E 2016 David Farrell
=head1 LICENSE
See LICENSE
=head1 REPOSITORY
L
=head2 BUGTRACKER
L
=cut