Revision 28664
- Date:
- 2009/10/08 20:49:07
- Files:
Legend:
- Added
- Removed
- Modified
-
docs/Perl6/Spec/S06-routines.pod
1924 1924 1925 1925 =back 1926 1926 1927 =head2 Signature Introspection 1927 1928 1929 A C<Signature> object can be introspected to find out the details of 1930 the parameters it is defined as expected. The C<.params> method will 1931 return a C<List> of C<Parameter> objects, which have the following 1932 readonly properties: 1933 1934 name The name of the lexical variable to bind to, if any 1935 type The main type (the one multi-dispatch sorts by) 1936 constraints Any further type constraints 1937 readonly True if parameter has C<is readonly> trait 1938 rw True if parameter has C<is rw> trait 1939 copy True if parameter has C<is copy> trait 1940 ref True if parameter has C<is ref> trait 1941 named True if the parameter is to be passed named 1942 named_names List of names a named parameter can be passed as 1943 slurpy True if the parameter is slurpy 1944 optional True if the parameter is optional 1945 default A closure returning the default value 1946 signature A nested signature to bind the argument against 1947 1948 Note that C<constraints> will be something that can be smart-matched 1949 against if it is defined; if there are many constraints it may be a 1950 C<Junction> of some sort, but if there is just one it may be simply 1951 that one thing. 1952 1953 Further, various things that appear in an original written signature 1954 will have been deconstructed a bit. For example, a signature like: 1955 1956 :(1) 1957 1958 Will introspect the same was as: 1959 1960 :(Int $ where 1) 1961 1962 And if we have: 1963 1964 subset Odd of Int where { $^n % 2 }; 1965 sub foo(Odd $x) { ... } 1966 1967 Then the signature of foo will be equivalent to something like: 1968 1969 :(Int $x where { $^n % 2 }) 1970 1971 That is, the refinement type will have been deconstructed into the 1972 part that nominal type that multiple dispatch uses for sorting the 1973 candidates and an additional constraint. 1974 1975 1928 1976 =head1 Advanced subroutine features 1929 1977 1930 1978 =head2 The C<return> function