This page was generated by Text::SmartLinks v0.01 at 2019-04-19 11:48:07 GMT.
(syn 8d47115)
  [ Index of Synopses ]


DRAFT: Synopsis 32: Setting Library - Basics


    Created: 19 Mar 2009 extracted from S29-functions.pod
    Last Modified: 29 June 2012
    Version: 5

The document is a draft.



The following are defined in the Mu class:

 class Mu {
     multi method defined ($self: --> Bool:D ) is export {...}
     multi method defined ( $self: ::role --> Bool:D ) is export { ... }
     multi method new(*%opts) { ... }
     method not() {...}
     method so() {...}
  multi method defined ( $self: --> Bool:D ) is export
  multi method defined ( $self: ::role --> Bool:D ) is export

defined returns true if the parameter has a value and that value is considered defined by its type, otherwise false is returned.

Same as Perl 5, only takes extra optional argument to ask if value is defined with respect to a particular role:

  defined($x, SomeRole);

A value may be defined according to one role and undefined according to another. Without the extra argument, defaults to the definition of defined supplied by the type of the object.

  multi method new(*%attrs) { }

Creates a new object of the same type as the object is called on, setting attributes with public accessors to the values provided by the named arguments to new.

  multi undefine( Any $thing is rw --> Any )

Takes any variable as a parameter and attempts to "remove" its definition. For simple scalar variables this means assigning the undefined value to the variable. For objects, this is equivalent to invoking their undefine method. For arrays, hashes and other complex data, this might require emptying the structures associated with the object.

In all cases, calling undefine on a variable should place the object in the same state as if it was just declared.

     method not() {...}
     method so() {...}

XXX Copied from S02 -- should it be deleted from there?

The definition of .Bool for the most ancestral type (that is, the Mu type) is equivalent to .defined. Since type objects are considered undefined, all type objects (including Mu itself) are false unless the type overrides the definition of .Bool to include undefined values. Instantiated objects default to true unless the class overrides the definition. Note that if you could instantiate a Mu it would be considered defined, and thus true. (It is not clear that this is allowed, however.)


The following are defined in the Any class:

 class Any is Mu {
     multi method clone (::T $self:, *%attributes --> T ) {...}
     multi method can ($self:, Str $method --> Callable ) {...}
     multi method does ($self:, $type --> Bool ) {...}
     multi method isa  ($self:, $type --> Bool ) {...}
     multi method perl ( Mu $o: --> Str ) is export {...}
     multi method warn ( Mu $o: --> Any ) is export {...}
 multi method can ($self:, Str $method --> Callable )

If there is a multi method of name $method that can be called on $self, then a closure is return which has $self bound to the position of the invocant.

Otherwise an undefined value is returned.

 multi method clone (::T $self --> T --> Any )
 multi method clone (::T $self, *%attributes --> T --> Any )

The first variant returns an independent copy of $o that is equivalent to $o.

The second variant does the same, but any named arguments override an attribute during the cloning process.

 multi method does ($self:, $type --> Bool )

Returns True if and only if $self conforms to type $type.

 multi method isa ($self:, $type --> Bool )

Returns True if a the invocant an instance of class $type, or of a subset type or a derived class (through inheritance) of $type.

 multi method perl ( Mu $o: --> Str ) is export

Returns a perlish representation of the object, so that calling EVAL on the returned string reproduces the object as accurately as possible.

 multi method warn ( Mu $o: --> Any ) is export

Throws a resumable warning exception, which is considered a control exception, and hence is invisible to most normal exception handlers. The outermost control handler will print the warning to $*ERR (which usually finds $PROCESS::ERR; see Synopsis 16: IPC / IO / Signals for details). After printing the warning, the exception is resumed where it was thrown. To override this behavior, catch the exception in a CONTROL block. A quietly {...} block is the opposite of a try {...} block in that it will suppress any warnings but pass fatal exceptions through.

To simply print to $*ERR, please use note instead. warn should be reserved for use in threatening situations when you don't quite want to throw an exception.


 role Pattern {
     method ACCEPTS($self:, $other) {...}

Used in smartmatching; see S03.


Scalar provides the basic tools for operating on undifferentiated scalar variables. All of the following are exported by default.


This is not really a method, but some kind of macro. See S12 for details.


    Rod Adams <[email protected]>
    Larry Wall <[email protected]>
    Aaron Sherman <[email protected]>
    Mark Stosberg <[email protected]>
    Carl Mäsak <[email protected]>
    Moritz Lenz <>
    Tim Nelson <[email protected]>
[ Top ]   [ Index of Synopses ]