~ubuntu-branches/ubuntu/precise/rakudo/precise

« back to all changes in this revision

Viewing changes to src/glue/enum.pm

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghedini
  • Date: 2011-05-17 11:31:09 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110517113109-rmfir654u1axbpt4
Tags: 0.1~2011.04-1
* New upstream release (Closes: #601862, #585762, #577502)
* New maintainer
* Switch to 3.0 (quilt) format
* Update dependencies (Closes: #584498)
* Update debian/copyright to lastest DEP5 revision
* Do not generate/install perl6 manpage (now done by the build system)
* Enable tests
* Bump Standards-Version to 3.9.2 (no changes needed)
* Do not install extra LICENSE files and duplicated docs
* Remove debian/clean (no more needed)
* Add Vcs-* fields in debian/control
* Rewrite (short) description
* Update upstream copyright years
* Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Note: this file probably wants to be in some Perl6::CompilerGuts namespace.
 
2
 
 
3
our sub SETUP_NAMED_ENUM($name, $values) {
 
4
    # For now, just install EnumMap under the main name.
 
5
    my @full_ns = Perl6::Grammar::parse_name($name);
 
6
    my ($shortname, @base_ns) = @full_ns;
 
7
    my $enumeration-object = (class {
 
8
        method WHAT { $enumeration-object }
 
9
        method enums { $values }
 
10
        method Str { $name }
 
11
        multi method roll($num = 1) { $values.roll($num) }
 
12
        multi method pick($num = 1) { $values.pick($num) }
 
13
        method ACCEPTS($topic) { $topic eqv any $values.values }
 
14
        method invert() { $values.invert }
 
15
    });
 
16
    pir::set_hll_global__vPSP(@base_ns, $shortname, $enumeration-object);
 
17
 
 
18
    for $values.kv -> $key, $value {
 
19
        my $enum-object = $value but role {
 
20
            method WHAT { $enumeration-object }
 
21
            method perl { $name ~ '::' ~ $key }
 
22
            method Str { $name ~ '::' ~ $key }
 
23
            method Stringy { $key }
 
24
            method key { $key }
 
25
            method value { $value }
 
26
            method pair { $key => $value }
 
27
            method kv { $key, $value }
 
28
            method defined { True }
 
29
        };
 
30
        pir::set_hll_global__vPSP(@full_ns, $key, $enum-object);
 
31
        pir::set_hll_global__vPSP(@base_ns, $key, $enum-object);
 
32
    }
 
33
}
 
34
 
 
35