GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Class::Method::Modifiers::Fast(3) User Contributed Perl Documentation Class::Method::Modifiers::Fast(3)

Class::Method::Modifiers::Fast - provides Moose-like method modifiers

    package Child;
    use parent 'Parent';
    use Class::Method::Modifiers::Fast;

    sub new_method { }

    before 'old_method' => sub {
        carp "old_method is deprecated, use new_method";
    };

    around 'other_method' => sub {
        my $orig = shift;
        my $ret = $orig->(@_);
        return $ret =~ /\d/ ? $ret : lc $ret;
    };

Method modifiers are a powerful feature from the CLOS (Common Lisp Object System) world.

"Class::Method::Modifiers::Fast" provides three modifiers: "before", "around", and "after". "before" and "after" are run just before and after the method they modify, but can not really affect that original method. "around" is run in place of the original method, with a hook to easily call that original method. See the "MODIFIERS" section for more details on how the particular modifiers work.

"before" is called before the method it is modifying. Its return value is totally ignored. It receives the same @_ as the the method it is modifying would have received. You can modify the @_ the original method will receive by changing $_[0] and friends (or by changing anything inside a reference). This is a feature!

"after" is called after the method it is modifying. Its return value is totally ignored. It receives the same @_ as the the method it is modifying received, mostly. The original method can modify @_ (such as by changing $_[0] or references) and "after" will see the modified version. If you don't like this behavior, specify both a "before" and "after", and copy the @_ during "before" for "after" to use.

"around" is called instead of the method it is modifying. The method you're overriding is passed in as the first argument (called $orig by convention). Watch out for contextual return values of $orig.

You can use "around" to:

Pass $orig a different @_
    around 'method' => sub {
        my $orig = shift;
        my $self = shift;
        $orig->($self, reverse @_);
    };
    
Munge the return value of $orig
    around 'method' => sub {
        my $orig = shift;
        ucfirst $orig->(@_);
    };
    
Avoid calling $orig -- conditionally
    around 'method' => sub {
        my $orig = shift;
        return $orig->(@_) if time() % 2;
        return "no dice, captain";
    };
    

Takatoshi Kitano <kitano.tk@gmail.com> gfx

Class::Method::Modifiers

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
2009-12-24 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.