Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 49 lines (38 sloc) 1.165 kb
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
use v6;

use Test;

plan 11;

=begin description

Test for

=end description

# L<S02/Bare identifiers/"$x.foo;">

class Foo {
    method foo {
        42
    }
    method bar() {
        101
    }
    method identity($x) {
        $x
    }
}

my $x = Foo.new();
is($x.foo, 42, 'called a method without parens');
is($x.foo(), 42, 'called a method without parens');
is($x.bar, 101, 'called a method with parens');
is($x.bar(), 101, 'called a method with parens');
is($x.identity("w00t"), "w00t", 'called a method with a parameter');

# L<S12/Methods/"You can replace the identifier with a quoted string">
eval_dies_ok(q{$x.'foo'}, 'indirect method call using quotes, no parens');
is($x.'bar'(), 101, 'indirect method call using quotes, with parens'); #OK use of quotes
is($x.'identity'('qwerty'), 'qwerty', 'indirect method call using quotes, with parameter'); #OK use of quotes
{
    my $name = 'foo';
    eval_dies_ok(q{$x."$name"}, 'indirect method call, no parens');
    is($x."$name"(), 42, 'indirect method call, with parens');
}
{
    my $name = 'identity';
    is($x."$name"('asdf'), 'asdf', 'indirect method call, with parameter');
}

# vim: syn=perl6
Something went wrong with that request. Please try again.