File: TestMethods.pm

package info (click to toggle)
librole-tiny-perl 1.001003-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 176 kB
  • sloc: perl: 657; makefile: 2
file content (23 lines) | stat: -rw-r--r-- 475 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package TestMethods;

use strict;
use warnings;

sub import {
    my ( $class, @methods ) = @_;
    my $target = caller;

    foreach my $method (@methods) {
        my $fq_method = $target . "::$method";
        no strict 'refs';
        *$fq_method = sub {
            local *__ANON__ = "__ANON__$fq_method";
            my $self = shift;
            return $self->{$method} unless @_;
            $self->{$method} = shift;
            return $self;
        };
    }
}

1;