• This repository has been archived on 31/Jan/2020
  • Stars
    star
    1
  • Language
    Perl
  • Created over 12 years ago
  • Updated over 12 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A light-weight Moose-like object system that makes it easy to create encapsulated, immutable objects

[[meta author="Delon Newman [email protected]"]]

NAME

Pudu - A light-weight Moose-like object system that makes it easy to create encapsulated, immutable objects

SYNOPSIS

package Animal {
    use Pudu;

    has name => ( is => 'rw' );

    method speak => sub {
        "grunt"
    };

    private {
        method hide => sub {
            "this is my hiding place"
        };
    };

    protected {
        method share => sub {
            "I share with my friends"
        };
    };
}

package Cat {
    use Pudu;
    is 'Animal';

    method speak => sub {
        "meow"
    };

    method reveal => sub {
        self->share . " and strangers";
    };

    method betray => sub {
        self->hide
    };
}

$a = Animal->new(name => 'Bruce');
$a->speak # => "grunt"
$a->hide  # dies
$a->share # dies

$c = Cat->new(name => 'Selina');
$c->speak  # => "meow"
$c->reveal # => "I share with my friends and strangers"
$c->betray # dies

FUNCTIONS

UTILITIES

  • clean

Removes all keywords from from the given namespace. It's used internally by Pudu::Object.

Example:

package Cat {
    use Pudu;

    has name => ( is => 'rw' );

    method speak => sub {
        "meow"
    };
}

my $c = Cat->new(name => "Selina");
$c->name;   # => "Selina"
$c->speak;  # => "meow"
$c->has;    # dies
$c->method; # dies

KEYWORDS

The following functions are all exported by default when using the Pudu module, and are designed to provide some syntactic sugar for the inner workings.

  • has

Keyword for defining attributes

Example:

package Point {
    use Pudu;

    has x => ( is => 'rw' );
    has y => ( is => 'rw' );
}
  • self

Keyword for recursively refering to the current object

Example:

package Cat {
    use Pudu;

    has name => ( is => 'ro' );

    method speak => sub {
        "Meow... my name is " . self->name;
    };
}
  • is

Keyword for establishing an 'is a' relationship between a child class and it's parents.

Example:

package Point3D {
    use Pudu;
    is 'Point';
}
  • does

Keyword for establishing a 'does' relationship between a class and a Role.

NOTE: this does not work yet

Example:

package LazyList {
    use Pudu;
    does 'Enumerable';
}
  • private

Keyword for designating a private scope

Example:

package Cat {
    use Pudu;

    private {
        method hide => sub {
            "hidden"
        };
    };
}

Cat->new->hide; # dies
  • protected

Keyword for designating a protected scope

Example:

package Animal {
    use Pudu;

    protected {
        method share => sub {
            "I share with my friends"
        };
    };
}

package Cat {
    use Pudu;
    is 'Animal';

    method reveal => sub {
        self->share . " and with strangers"
    };
}

Animal->new->share; # dies
Cat->new->reveal;   # => "I share with my friends and with strangers"
  • method

Keyword for defining a method

Example:

package Dog {
    use Pudu;

    method speak => sub {
        "bark"
    };
}

AUTHOR

Delon Newman [email protected]

SEE ALSO

Moose, Mouse, Moo, Mo, Class::Closure, Devel::EnforceEncapsulation

More Repositories

1

invokable

Objects are functions! Treat any Object or Class as a Proc (like Enumerable but for Procs).
Ruby
43
star
2

mini-levenshtein

Simple, fast Levenshtein distance and similarity ratio for Ruby
C
27
star
3

activerecord-setops

Union, Intersect, and Difference set operations for ActiveRecord (also, SQL's UnionAll).
Ruby
21
star
4

magbot

A CLI application for fetching media from jw.org feeds
Perl
9
star
5

zera-5

A light-weight Clojure interpreter
JavaScript
8
star
6

activerecord-pull

A simple query interface for pulling deeply nested data from records.
Ruby
4
star
7

contracts-gen

Generate data from contracts
Ruby
2
star
8

dragnet

A work-in-progress system for programmable surveys, and forms.
Ruby
2
star
9

ALJAFP

A Little Java, A Few Patterns
Java
1
star
10

piglatin

Pig Latin translator
Perl
1
star
11

cantor

Relational Algebra and Reporting
Ruby
1
star
12

atomjs

Clojure Atoms for Javascript. Shared, synchronous, independent state. A fork of https://github.com/cjohansen/js-atom.
JavaScript
1
star
13

sinatra-rest-service-auth

Ruby
1
star
14

sleepr

Stop hacking and get some sleep
Perl
1
star
15

connect4

JavaScript
1
star
16

tether

Ruby
1
star
17

tetris.js

An (incomplete) tetris clone
JavaScript
1
star
18

wonderscript-alpha

A lisp for the web
TypeScript
1
star
19

periscope

A Perl Module for viewing sites through a periscope
Perl
1
star
20

pandora-periscope

A Periscope for Pandora
Perl
1
star
21

java-posix

POSIX for Java a clone (for posterity, I have no intention of maintaining this) imported from tarball found here: http://www.bmsi.com/java/posix/index.html
Java
1
star
22

Makakilo-Elementary

Ruby
1
star
23

sleepr-preferences

Preferences dialog for sleepr
Python
1
star
24

yugo

An experimental tool for converting legacy ColdFusion applications into Ruby / Rack applications.
Ruby
1
star
25

talks

1
star
26

asdf-vm.el

asdf-vm integration for Emacs
Emacs Lisp
1
star
27

kigo

Ruby is already pretty lispy let's take it the rest of the way.
Ruby
1
star
28

rubygems

A fork to add offline installation features, all changes are in offline branch
Ruby
1
star