/
Mo.pm
65 lines (51 loc) · 1.04 KB
/
Mo.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
##
# name: Mo
# abstract: Micro Objects
# author: Ingy döt Net <ingy@cpan.org>
# license: perl
# copyright: 2011
use 5.010;
package Mo;
use strict;
use warnings;
our $VERSION = '0.10';
use base 'Exporter';
our @EXPORT = qw(extends has);
sub import {
my $class = $_[0];
my $pkg = caller;
strict->import;
warnings->import;
no strict 'refs';
push @{"${pkg}::ISA"}, $class;
goto &Exporter::import;
}
sub new {
my $class = shift;
my $self = bless {@_}, $class;
}
sub has {
my $name = shift;
my $pkg = caller;
my $has = sub {
my $self = shift;
return $self->{$name} unless @_;
return $self->{$name} = $_[0];
};
no strict 'refs';
*{"${pkg}::$name"} = $has;
}
sub extends {
my $parent = shift;
my $pkg = caller;
no strict 'refs';
@{"${pkg}::ISA"} = ($parent);
}
1;
=head1 SYNOPSIS
package Reaper;
use Mo 'Cow Bell';
extends 'SNL';
has noise => (is =>'ro');
=head1 DESCRIPTION
Moose led to Mouse led to Moo led to Mo. M, anyone?