See Original text in context
method new(:!, :! --> Proxy)
Creates a new Proxy
object. &FETCH
is called with one argument (the proxy object) when the value is accessed, and must return the value that the fetch produces. &STORE
is called with two arguments (the proxy object, and the new value) when a new value is stored in the container.
See Original text in context
Same as IO::Path.new
, except :$SPEC
cannot be set and defaults to IO::Spec::QNX
, regardless of the operating system the code is being run on.
See Original text in context
method new( int )
Initialize the semaphore with the number of permitted accesses. E.g. when set to 2, program threads can pass the acquire method twice until it blocks on the third time acquire is called.
See Original text in context
multi method new()multi method new()
Num.new
without argument will create a Num
with the value 0e0
. With an argument, it will be coerced to Num
and then returned.
say Num.new(⅓); # OUTPUT: «0.3333333333333333»
See Original text in context
Same as IO::Path.new
, except :$SPEC
cannot be set and defaults to IO::Spec::Cygwin
, regardless of the operating system the code is being run on.
See Original text in context
method new(*@)
Returns Nil
See Original text in context
multi method new(Any )multi method new(Any \value --> Int)multi method new(int \value --> Int)
The first form will throw an exception; the second and third form will create an new Int from the actual integer value contained in the variable.
See Original text in context
method new(Num , Str )
The constructor requires both the Num
and the Str
value, when constructing one directly the values can be whatever is required:
my = NumStr.new(42.1e0, "forty two and a bit");say +; # OUTPUT: «42.1»say ~; # OUTPUT: «"forty two and a bit"»
See Original text in context
method new(Complex , Str )
The constructor requires both the Complex
and the Str
value, when constructing one directly the values can be whatever is required:
my = ComplexStr.new(42+0i, "forty two (but complicated)");say +; # OUTPUT: «42+0i»say ~; # OUTPUT: «"forty two (but complicated)"»
See Original text in context
multi method new(Str , IO::Spec : = , Str() : = )multi method new(:!, : = '.', : = ''IO::Spec : = , Str() : =)
Creates a new IO::Path
object from a path string (which is being parsed for volume, directory name and basename), or from volume, directory name and basename passed as named arguments.
The path's operation will be performed using :$SPEC
semantics (defaults to current $*CWD
) and will use :$CWD
as the directory the path is relative to (defaults to $*CWD
).
If $path
includes the null byte, it will throw an Exception with a "Cannot use null character (U+0000) as part of the path" message.
See Original text in context
method new(NuT , DeT --> Rational)
Creates a new rational object from numerator and denominator, which it normalizes to the lowest terms. The $denominator
can be zero, in which case the numerator is normalized to -1
, 0
, or 1
depending on whether the original is negative, zero, or positive, respectively.
See Original text in context
method new(, :)
Creates a new Distribution::Hash
instance from the metadata contained in $hash
. All paths in the metadata will be prefixed with :$prefix
.
See Original text in context
method new( :, :, :)
This is the default constructor for X:NYI
which can take three parameters with obvious meanings.
my = Nothing.new;.ventured("Nothing", "Gained");
In this case, we are throwing an exception that indicates that the ventured
routine has not been implemented; we use the generic &?ROUTINE.name
to not tie the exception to the method name in case it is changed later on. This code effectively throws this exception
# OUTPUT:# ventured not yet implemented. Sorry.# Did you mean: gained?# Workaround: Implement it yourself# in method ventured at NYI.p6 line 6# in block <unit> at NYI.p6 line 14
Using the exception properties, it composes the message that we see there.
See Original text in context
multi method new(Blob:)multi method new(Blob: Blob )multi method new(Blob: int )multi method new(Blob: )multi method new(Blob: *)
Creates an empty Blob
, or a new Blob
from another Blob
, or from a list of integers or values (which will have to be coerced into integers):
my = Blob.new([1, 2, 3]);say Blob.new(<1 2 3>); # OUTPUT: «Blob:0x<01 02 03>»
See Original text in context
method new(*)
Creates a new PackageHOW
.
See Original text in context
method new(Rat , Str )
The constructor requires both the Rat
and the Str
value, when constructing one directly the values can be whatever is required:
my = RatStr.new(42.1, "forty two and a bit");say +; # OUTPUT: «42.1»say ~; # OUTPUT: «"forty two and a bit"»
See Original text in context
method new(Int , Str )
The constructor requires both the Int
and the Str
value, when constructing one directly the values can be whatever is required:
my = IntStr.new(42, "forty two");say +; # OUTPUT: «42»say ~; # OUTPUT: «"forty two"»
See Original text in context
multi method new(*)multi method new($, *@)
Default method for constructing (create + initialize) new objects of a class. This method expects only named arguments which are then used to initialize attributes with accessors of the same name.
Classes may provide their own new
method to override this default.
new
triggers an object construction mechanism that calls submethods named BUILD
in each class of an inheritance hierarchy, if they exist. See the documentation on object construction for more information.
See Original text in context
multi method new(, , , : --> Date)multi method new(:!, : = 1, : = 1 --> Date)multi method new(Str --> Date)multi method new(Instant --> Date)multi method new(DateTime --> Date)
Creates a new Date
object, either from a triple of (year, month, day) that can be coerced to integers, or from a string of the form YYYY-MM-DD
(ISO 8601), or from an Instant or DateTime object. Optionally accepts a formatter as a named parameter.
my = Date.new(2042, 1, 1);= Date.new(year => 2042, month => 1, day => 1);= Date.new("2042-01-01");= Date.new(Instant.from-posix: 1482155532);= Date.new(DateTime.now);
Since Rakudo 2022.03, the "day" argument can also be a callable, with *
representing the last day in a month, and the possibility of getting to the day counting from the last one:
say Date.new(2042, 2, *); # OUTPUT: «2042-02-28»say Date.new(2044, 2, *); # OUTPUT: «2044-02-29»
See Original text in context
proto method new(Seq: |)multi method new(Seq: Iterator )multi method new(Seq:)
Creates a new Seq
object from the supplied iterator passed as the single argument. Creates an empty Seq
if called with no argument.
See Original text in context
multi method new(*@ (, *), :, :, :, :,: = False,: = False --> Proc::Async)multi method new( :, :, :, :, :, :,: = False,: = False --> Proc::Async)
Creates a new Proc::Async
object with external program name or path $path
and the command line arguments @args
.
If :w
is passed to new
, then a pipe to the external program's standard input stream (stdin
) is opened, to which you can write with write
and say
.
The :enc
specifies the encoding for streams (can still be overridden in individual methods) and defaults to utf8
.
If :translate-nl
is set to True
(default value), OS-specific newline terminators (e.g. \r\n
on Windows) will be automatically translated to \n
.
If :arg0
is set to a value, that value is passed as arg0 to the process instead of the program name.
The :started
attribute is set by default to False
, so that you need to start the command afterwards using .start
. You probably don't want to do this if you want to bind any of the handlers, but it's OK if you just need to start a external program immediately.
On Windows the flag $win-verbatim-args
disables all automatic quoting of process arguments. See this blog for more information on windows command quoting. The flag is ignored on all other platforms. The flag was introduced in Rakudo version 2020.06 and is not present in older releases. By default, it's set to False
, in which case arguments will be quoted according to Microsoft convention.
See Original text in context
method new(Proc:: = '-',: = '-',: = '-',Bool : = False,Bool : = True,Bool : = False,Str : = 'UTF-8',Str : = "\n",--> Proc)sub shell(,: = '-',: = '-',: = '-',Bool : = False,Bool : = True,Bool : = False,Str : = 'UTF-8',Str : = "\n",: = ,Hash() : =--> Proc)
new
creates a new Proc
object, whereas run
or shell
create one and spawn it with the command and arguments provided in @args
or $cmd
, respectively.
$in
, $out
and $err
are the three standard streams of the to-be-launched program, and default to "-"
meaning they inherit the stream from the parent process. Setting one (or more) of them to True
makes the stream available as an IO::Pipe object of the same name, like for example $proc.out
. You can set them to False
to discard them. Or you can pass an existing IO::Handle object (for example IO::Pipe
) in, in which case this handle is used for the stream.
Please bear in mind that the process streams reside in process variables, not in the dynamic variables that make them available to our programs. Thus, modifying the dynamic filehandle variables (such as $*OUT
) inside the host process will have no effect in the spawned process, unlike $*CWD
and $*ENV
, whose changes will be actually reflected in it.
my = "/tmp/program.raku";my =spurt , ;.put: "1. standard output before doing anything weird";.put: "3. everything should be back to normal";# OUTPUT# 1. standard output before doing anything weird# /tmp/program.raku: This goes to standard output# 3. everything should be back to normal# /tmp/out.txt will contain:# 2. temp redefine standard output before this message
This program shows that the program spawned with shell
is not using the temporary $*OUT
value defined in the host process (redirected to /tmp/out.txt
), but the initial STDOUT
defined in the process.
$bin
controls whether the streams are handled as binary (i.e. Blob object) or text (i.e. Str objects). If $bin
is False, $enc
holds the character encoding to encode strings sent to the input stream and decode binary data from the output and error streams.
With $chomp
set to True
, newlines are stripped from the output and err streams when reading with lines
or get
. $nl
controls what your idea of a newline is.
If $merge
is set to True, the standard output and error stream end up merged in $proc.out
.
See Original text in context
multi method new(Failure:)multi method new(Failure:)multi method new(Failure: Exception \exception)multi method new(Failure: )multi method new(Failure: |cap (*))
Returns a new Failure
instance with payload given as argument. If called without arguments on a Failure
object, it will throw; on a type value, it will create an empty Failure
with no payload. The latter can be either an Exception or a payload for an Exception
. A typical payload would be a Str
with an error message. A list of payloads is also accepted.
my = Failure.new(now.DateTime, 'WELP‼');say ;CATCH# OUTPUT: «X::AdHoc: 2017-09-10T11:56:05.477237ZWELP‼»
See Original text in context
multi method new(Int :!, Int : = 1, Int : = 1,Int : = 0, Int : = 0, : = 0,Int : = 0, :)multi method new(Date :!,Int : = 0, Int : = 0, : = 0,Int : = 0, :)multi method new(Int() , Int() , Int() ,Int() , Int , ,Int() : = 0, :)multi method new(Instant , :=0, :)multi method new(Numeric , :=0, :)multi method new(Str , :=0, :)
Creates a new DateTime
object. One option for creating a new DateTime object is from the components (year, month, day, hour, ...) separately. Another is to pass a Date object for the date component, and specify the time component-wise. Yet another is to obtain the time from an Instant, and only supply the time zone and formatter. Or instead of an Instant you can supply an Numeric as a UNIX timestamp.
You can also supply a Str formatted in ISO 8601 timestamp notation or as a full RFC 3339 date and time. Strings should be formatted as yyyy-mm-ddThh:mm:ssZ
or yyyy-mm-ddThh:mm:ss+0100
. We are somewhat less restrictive than the ISO 8601 standard, as we allow Unicode digits and mixing of condensed and extended time formats.
An invalid input string throws an exception of type X::Temporal::InvalidFormat. If you supply a string that includes a time zone and supply the timezone
named argument, an exception of type X::DateTime::TimezoneClash is thrown.
my = DateTime.new(year => 2015,month => 1,day => 1,hour => 1,minute => 1,second => 1,timezone => 1);= DateTime.new(date => Date.new('2015-12-24'),hour => 1,minute => 1,second => 1,timezone => 1);= DateTime.new(2015, 1, 1, # First January of 20151, 1, 1); # Hour, minute, second with default time zone= DateTime.new(now); # Instant.# from a Unix timestampsay = DateTime.new(1470853583.3); # OUTPUT: «2016-08-10T18:26:23.300000Z»= DateTime.new("2015-01-01T03:17:30+0500") # Formatted string
Since Rakudo release 2022.03, the day
parameter can be a Callable
, with *
returning the last day in the month, and *-n
returning the last but n
.
See Original text in context
method new(\volume, \dirname, \basename)
Create a new IO::Path::Parts
object with \volume
, \dirname
and \basename
as respectively the volume, directory name and basename parts.
See Original text in context
method new(:!, Bool : = False, Str : = '<anon>' --> Thread)
Creates and returns a new Thread
, without starting it yet. &code
is the code that will be run in a separate thread.
$name
is a user-specified string that identifies the thread.
If $app_lifetime
is set to True
, then the thread is killed when the main thread of the process terminates. If set to False
, the process will only terminate when the thread has finished.
See Original text in context
multi method new()multi method new(Int )multi method new(Mu \ex)multi method new(Mu \ex, Int )multi method new(List )multi method new(List , Int )
Creates a new backtrace, using its calling location as the origin of the backtrace or the $offset
that is passed as a parameter. If an object or a list (that will already contain a backtrace in list form) is passed, they will be used instead of the current code.
my = Backtrace.new;
See Original text in context
method new()
The Supplier
constructor.
See Original text in context
method new(Telemetry::Sampler: --> Telemetry::Sampler)
The new
method takes a list of instruments. If no instruments are specified, then it will look at the RAKUDO_TELEMETRY_INSTRUMENTS
environment variable to find specification of instruments. If that is not available either, then Telemetry::Instrument::Usage
and Telemetry::Instrument::ThreadPool
will be assumed.
Instruments can be specified by either the type object of the instrument class (e.g. Telemetry::Instrument::Usage
) or by a string, in which case it will be automatically prefixed with "Telemetry::Instrument::", so "Usage" would be the same as Telemetry::Instrument::Usage
.
See Original text in context
method new(*)
Creates a new Map from a list of alternating keys and values, with the same semantics as described in the Hashes and maps documentation, but also accepts Pair
s instead of separate keys and values. Use the grouping operator or quote the key to ensure that a literal pair is not interpreted as a named argument.
my = Map.new('a', 1, 'b', 2);# WRONG: :b(2) interpreted as named argumentsay Map.new('a', 1, :b(2)).keys; # OUTPUT: «(a)»# RIGHT: :b(2) interpreted as Pair because of extra parenthesessay Map.new( ('a', 1, :b(2)) ).keys.sort; # OUTPUT: «(a b)»# RIGHT: 'b' => 2 always creates a Pairsay Map.new('a', 1, 'b' => 2).keys.sort; # OUTPUT: «(a b)»
A shorthand syntax for creating Maps is provided:
my is Map = 'a', 1, 'b', 2;
See Original text in context
method new()
The Supplier
constructor.
See Original text in context
method new(:!)
Takes a single required attribute what. It is unlikely that you will ever need to construct one of these objects yourself.
See Original text in context
Same as IO::Path.new
, except :$SPEC
cannot be set and defaults to IO::Spec::Unix
, regardless of the operating system the code is being run on.
See Original text in context
CX::Warn
objects are created when a warning is thrown in any block.
See Original text in context
method new(IO::Path , IO::Path : = IO::Path)
Creates a new Distribution::Path
instance from the META6.json
file found at the given $prefix
, and from which all paths in the metadata will be prefixed with. :$meta-file
may optionally be passed if a filename other than META6.json
needs to be used.
See Original text in context
method new(* --> Uni)
Creates a new Uni
instance from the given codepoint numbers.
See Original text in context
multi method new(Real , Real --> Complex)
Creates a new Complex
object from real and imaginary parts.
my = Complex.new(1, 1);say ; # OUTPUT: «1+1i»
When created without arguments, both parts are considered to be zero.
say Complex.new; # OUTPUT: «0+0i»
See Original text in context
multi method new(Pair: Mu , Mu )multi method new(Pair: Mu :, Mu :)
Constructs a new Pair object.
See Original text in context
method new(*, :, : = True,: = ["\n", "\r\n"], Str :, Bool :)
Creates a new IO::CatHandle object.
The @handles
positional argument indicates a source of handles for the IO::CatHandle
to read from and can deal with a mixed collection of Cool, IO::Path, and IO::Handle (including IO::Pipe) objects. As input from IO::CatHandle is processed (so operations won't happen during .new
call, but only when @handles
' data is needed), it will walk through the @handles
list, processing each argument as follows:
IO::Path objects will be opened for reading using the IO::CatHandle's (invocant's) attributes for open
calls;
un-opened IO::Handle objects will be opened in the same fashion as IO::Path objects;
and already opened IO::Handle objects will have all of their attributes set to the attributes of the invocant IO::CatHandle.
In short, all the @handles
end up as IO::Handle objects opened in the same mode and with the same attributes as the invocant IO::CatHandle.
See .on-switch
method for details on the :&on-switch
named argument, which by default is not set.
The :$encoding
named argument specifies the handle's encoding and accepts the same values as IO::Handle.encoding
. Set :$bin
named argument to True
if you wish the handle to be in binary mode. Attempting to specify both a defined :$encoding
and a True
:$bin
is a fatal error resulting in X::IO::BinaryAndEncoding
exception thrown. If neither :$encoding
is set nor :$bin
set to a true value, the handle will default to utf8
encoding.
The :$chomp
and :$nl-in
arguments have the same meaning as in IO::Handle and take and default to the same values.
See Original text in context
multi method new(Junction: \values, Str :!)multi method new(Junction: Str \type, \values)
These constructors build a new junction from the type that defines it and a set of values.
my = Junction.new(<Þor Oðinn Loki>, type => "all");my = Junction.new( "one", 1..6 )
The main difference between the two multis is how the type of the Junction
is passed as an argument; either positionally as the first argument, or as a named argument using type
.
See Original text in context
multi method new(:,:,: = PF_INET,: = 'utf-8',: = "\r\n",--> IO::Socket::INET)multi method new(:,:,: = PF_INET,:,: = 'utf-8',: = "\r\n",--> IO::Socket::INET)
Creates a new socket.
If :$listen
is True, creates a new socket that listen on :$localhost
(which can be an IP address or a domain name) on port :$localport
; in other words the :$listen
flag determines the server mode of the socket. Otherwise (i.e., :$listen
is False
), the new socket opens immediately a connection to :$host
on port :$port
.
:$family
defaults to PF_INET
constant for IPv4, and can be set to PF_INET6
constant for IPv6.
For text operations (such as #method lines and #method get), :$encoding
specifies the encoding, and :$nl-in
determines the character(s) that separate lines.
See Original text in context
method new(Str )
Creates a Version
from a string $s
. The string is combed for the numeric, alphabetic, and wildcard components of the version object. Any characters other than alphanumerics and asterisks are assumed to be equivalent to a dot. A dot is also assumed between any adjacent numeric and alphabetic characters.
See Original text in context
Same as IO::Path.new
, except :$SPEC
cannot be set and defaults to IO::Spec::Win32
, regardless of the operating system the code is being run on.