tagged release 0.6.4
[parrot.git] / languages / perl6 / src / classes / Pair.pir
blob2aa69b0b3c520c5d32185e00cbf641767bc48c92
1 ## $Id$
3 =head1 NAME
5 src/classes/Pair.pir - methods for the Pair class
7 =head1 Methods
9 =over 4
11 =cut
13 .namespace ['Perl6Pair']
15 .sub 'onload' :anon :load :init
16     .local pmc p6meta
17     p6meta = get_hll_global ['Perl6Object'], '$!P6META'
18     p6meta.'new_class'('Perl6Pair', 'parent'=>'Any', 'attr'=>'$!key $!value', 'name'=>'Pair')
19 .end
21 =item key
23 Gets the key of the pair.
25 =cut
27 .sub 'key' :method
28     $P0 = getattribute self, '$!key'
29     .return ($P0)
30 .end
33 =item value
35 Gets the value of the pair.
37 =cut
39 .sub 'value' :method
40     $P0 = getattribute self, '$!value'
41     .return ($P0)
42 .end
45 =item get_string()  (vtable method)
47 Stringify the Pair.
49 =cut
51 .sub 'get_string' :method :vtable
52     $S0 = self.'key'()
53     concat $S0, "\t"
54     $S1 = self.'value'()
55     concat $S0, $S1
56     .return ($S0)
57 .end
60 =item perl
62 Returns a Perl code representation of the pair.
64 =cut
66 .sub perl :method
67     # Get key and value.
68     $P0 = self.'key'()
69     $P1 = self.'value'()
71     # Get perl representation
72     $S0 = $P0.'perl'()
73     $S1 = $P1.'perl'()
75     # build result
76     .local string result
77     result = concat '(', $S0
78     result .= ' => '
79     result .= $S1
80     result .= ')'
81     .return (result)
82 .end
85 .namespace []
87 .sub 'infix:=>'
88     .param pmc key
89     .param pmc value
90     key = key.'item'()
91     value = value.'item'()
92     $P0 = get_hll_global 'Pair'
93     .return $P0.'new'('key'=>key, 'value'=>value)
94 .end
97 =back
99 =cut
101 # Local Variables:
102 #   mode: pir
103 #   fill-column: 100
104 # End:
105 # vim: expandtab shiftwidth=4 ft=pir: