Changeset 5357


Ignore:
Timestamp:
06/19/09 07:39:59 (3 years ago)
Author:
azawawi
Message:

[Perl 6] The Point class in Perl 6 (template)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre-Plugin-Perl6/lib/Padre/Plugin/Perl6/share/templates/p6_class.p6

    r5354 r5357  
    11use v6; 
    22 
    3 class Foo { 
     3=begin Pod 
     4    An example of a Perl 6 class 
     5=end Pod 
     6class Point { 
     7    # attributes;  
     8    # note that variable initialization is not automatic in Perl 6 
     9    has $.x = 0; 
     10    has $.y = 0; 
     11 
     12    # a method to move to a new location 
     13    method move($new_x, $new_y) { 
     14        $.x = $new_x; 
     15        $.y = $new_y; 
     16    } 
     17     
     18    method to_string() { 
     19        return $.x ~ "," ~ $.y;  
     20    } 
    421} 
     22 
     23# Create a point and initializes its attributes 
     24my $pt1 = Point.new(); 
     25my $pt2 = Point.new(:x(7), :y(8)); 
     26say $pt1.to_string; 
     27say $pt2.to_string; 
Note: See TracChangeset for help on using the changeset viewer.