Changeset 3465

Show
Ignore:
Timestamp:
05/19/05 22:22:58 (4 years ago)
Author:
chromatic
svk:copy_cache_prev:
5016
Message:

First stab at making $?CLASS and $?PACKAGE work. It compiles anyway.

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Eval.hs

    r3443 r3465  
    239239getMagical "$?MODULE"   = constSym "main" 
    240240getMagical "$?OS"       = constSym $ getConfig "osname" 
     241getMagical "$?CLASS"    = constSym =<< asks envPackage 
     242getMagical "$?PACKAGE"  = constSym =<< asks envPackage 
    241243getMagical _            = return Nothing 
    242244 
  • t/oo/magical_vars.t

    r3304 r3465  
    44use Test; 
    55 
    6 plan 9; 
     6plan 11; 
    77 
    88class Foo { 
    99  method get_self()  { $?SELF } 
    10   method get_class() { eval '$?CLASS' } 
     10  method get_class() { $?CLASS } 
     11  method get_package() { $?PACKAGE } 
    1112  method dummy()     { 42 } 
    1213} 
     
    1415role Bar { 
    1516  method get_self()  { $?SELF } 
    16   method get_class() { eval '$?CLASS' } 
    17   method get_role()  { eval '$?ROLE'  } 
     17  method get_class() { $?CLASS } 
     18  method get_role()  { $?ROLE } 
     19  method get_package() { $?PACKAGE } 
    1820  method dummy()     { 42 } 
    1921} 
     
    2426  my $foo_obj = Foo.new; 
    2527  my $class   = $foo_obj.get_class; 
     28  my $package = $foo_obj.get_package; 
     29  is( $package, 'Foo', '$?PACKAGE should be the package name' ); 
    2630 
    27   is $class ~~ Foo, 'the thing returned by $?CLASS in our class smartmatches against our class'; 
     31  ok( $class ~~ Foo, 'the thing returned by $?CLASS in our class smartmatches against our class' ); 
    2832  my $fourty_two; 
    2933  lives_ok { $fourty_two = $class.new.dummy }, 
    30     'the class returned by $?CLASS in our class way really our class (1)'; 
     34    'the class returned by $?CLASS in our class was really our class (1)'; 
    3135  is $fourty_two, 42, 'the class returned by $?CLASS in our class way really our class (2)'; 
    3236} 
     
    4246  my $bar   = SimpleClass.new; 
    4347  my $class = $bar.get_class; 
     48  my $package = $bar.get_package; 
     49 
     50  is( $package, 'SimpleClass', '$?PACKAGE should be the package name' ); 
    4451 
    4552  is $class ~~ SimpleClass, 'the thing returned by $?CLASS in our role smartmatches against our class';