Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 36 lines (27 sloc) 0.605 kb
8a5b9bf [t] set some svn attributes
moritz authored
1 use v6;
2
3 use Test;
4
5 plan 4;
6
6714432 [gsoc_spectest] adding smartlink for tests of $!method syntax
Auzon authored
7 # L<S12/Methods/"For a call on your own private method">
8
8a5b9bf [t] set some svn attributes
moritz authored
9 class Counter {
10 has $!x;
11 method init { $!x = 41 }
12 method get { $!x }
13 method inc { $!x++ }
14 }
15
16 my $c = Counter.new();
17 try {
18 $c.x
19 }
20 ok($!, 'no public accessor for private attribute');
21 $c.init();
22 is($c.get(), 41, 'can assign and get from within the class');
23 $c.inc();
24 is($c.get(), 42, 'can auto-increment an attribute');
25
26
27 class WithAlias {
28 has $x;
29 method set($a) { $x = $a }
30 method get { $!x }
31 }
32
33 my $wa = WithAlias.new();
34 $wa.set(99);
35 is($wa.get, 99, 'has with no twigil creates alias');
Something went wrong with that request. Please try again.