File: TestMethods.pm

package info (click to toggle)
librole-basic-perl 0.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 252 kB
  • sloc: perl: 1,725; makefile: 7
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;