PerlObject
open class PerlObject : PerlValue, PerlScalarConvertible
Provides a safe wrapper for Perl objects (blessed references). Performs reference counting on initialization and deinitialization.
Any Perl object of unregistered type will be imported to Swift
as an instance of this class. To provide clean API to your
Perl object implement class derived from PerlObject
, make it
conforming to PerlNamedClass
and supply it with methods and
calculated attributes providing access to Perl methods of your
object. Use register
method on startup to enable automatical
conversion of Perl objects of class perlClassName
to instances
of your Swift class.
For example:
final class URI : PerlObject, PerlNamedClass {
static let perlClassName = "URI"
convenience init(_ str: String) throws {
try self.init(method: "new", args: [str])
}
convenience init(_ str: String, scheme: String) throws {
try self.init(method: "new", args: [str, scheme])
}
convenience init(copyOf uri: URI) {
try! self.init(uri.call(method: "clone") as PerlScalar)
}
var scheme: String? { return try! call(method: "scheme") }
func scheme(_ scheme: String) throws -> String? { return try call(method: "scheme", scheme) }
var path: String {
get { return try! call(method: "path") }
set { try! call(method: "path", newValue) as Void }
}
var asString: String { return try! call(method: "as_string") }
func abs(base: String) -> String { return try! call(method: "abs", base) }
func rel(base: String) -> String { return try! call(method: "rel", base) }
var secure: Bool { return try! call(method: "secure") }
}
-
Creates a new object by calling its Perl constructor.
Use this
init
only to construct instances of subclasses conforming toPerlNamedClass
.The recomended way is to wrap this constructor invocations by implementing more concrete initializers which hide Perl method calling magic behind.
Let’s imagine a class:
final class URI : PerlObject, PerlNamedClass { static let perlClassName = "URI" convenience init(_ str: String) throws { try self.init(method: "new", args: [str]) } }
Then Swift expression:
let uri = URI("https://my.mail.ru/music")
will be equal to Perl:
my $uri = URI->new("https://my.mail.ru/music")
Declaration
Swift
public convenience init(method: String, args: [PerlScalarConvertible?], perl: PerlInterpreter = .current) throws
Parameters
method
A name of the constuctor. Usually it is new.
args
Arguments to pass to the constructor.
perl
The Perl interpreter.
-
Casts an instance of
PerlScalar
toPerlObject
.Throws
If underlying SV is not an object.Declaration
Swift
public convenience init(_ scalar: PerlScalar) throws
-
Returns the specified Perl global or package object with the given name (so it won’t work on lexical variables). If the variable does not exist then
nil
is returned.Declaration
Swift
public convenience init?(get name: String, perl: PerlInterpreter = .current) throws
-
A textual representation of the SV, suitable for debugging.
Declaration
Swift
public override var debugDescription: String
-
Registers class
swiftClass
as a counterpart of Perl’s class with nameclassname
.Declaration
Swift
public static func register<T>(_ swiftClass: T.Type, as classname: String) where T : PerlObject, T : PerlNamedClass
-
Declaration
Swift
public required init(noincUnchecked svc: UnsafeSvContext)
-
Declaration
Swift
public required init(incUnchecked svc: UnsafeSvContext)
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call(method: String, args: [PerlScalarConvertible?], context: PerlSub.VoidContext = .void) throws -> Void
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call(method: PerlScalar, args: [PerlScalarConvertible?], context: PerlSub.VoidContext = .void) throws -> Void
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call(method: String, _ args: PerlScalarConvertible?..., context: PerlSub.VoidContext = .void) throws -> Void
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call(method: PerlScalar, _ args: PerlScalarConvertible?..., context: PerlSub.VoidContext = .void) throws -> Void
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call<R : PerlScalarConvertible>(method: String, args: [PerlScalarConvertible?], context: PerlSub.ScalarContext = .scalar) throws -> R
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call<R : PerlScalarConvertible>(method: PerlScalar, args: [PerlScalarConvertible?], context: PerlSub.ScalarContext = .scalar) throws -> R
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call<R : PerlScalarConvertible>(method: String, _ args: PerlScalarConvertible?..., context: PerlSub.ScalarContext = .scalar) throws -> R
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call<R : PerlScalarConvertible>(method: PerlScalar, _ args: PerlScalarConvertible?..., context: PerlSub.ScalarContext = .scalar) throws -> R
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call<R : PerlScalarConvertible>(method: String, args: [PerlScalarConvertible?], context: PerlSub.ScalarContext = .scalar) throws -> R?
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call<R : PerlScalarConvertible>(method: PerlScalar, args: [PerlScalarConvertible?], context: PerlSub.ScalarContext = .scalar) throws -> R?
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call<R : PerlScalarConvertible>(method: String, _ args: PerlScalarConvertible?..., context: PerlSub.ScalarContext = .scalar) throws -> R?
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call<R : PerlScalarConvertible>(method: PerlScalar, _ args: PerlScalarConvertible?..., context: PerlSub.ScalarContext = .scalar) throws -> R?
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call<R : PerlScalarConvertible>(method: String, args: [PerlScalarConvertible?], context: PerlSub.ArrayContext) throws -> R
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call<R : PerlScalarConvertible>(method: PerlScalar, args: [PerlScalarConvertible?], context: PerlSub.ArrayContext) throws -> R
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call<R : PerlScalarConvertible>(method: String, _ args: PerlScalarConvertible?..., context: PerlSub.ArrayContext) throws -> R
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call<R : PerlScalarConvertible>(method: PerlScalar, _ args: PerlScalarConvertible?..., context: PerlSub.ArrayContext) throws -> R
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call<R : PerlScalarConvertible>(method: String, args: [PerlScalarConvertible?], context: PerlSub.ArrayContext) throws -> R?
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call<R : PerlScalarConvertible>(method: PerlScalar, args: [PerlScalarConvertible?], context: PerlSub.ArrayContext) throws -> R?
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call<R : PerlScalarConvertible>(method: String, _ args: PerlScalarConvertible?..., context: PerlSub.ArrayContext) throws -> R?
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call<R : PerlScalarConvertible>(method: PerlScalar, _ args: PerlScalarConvertible?..., context: PerlSub.ArrayContext) throws -> R?
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call<R0 : PerlScalarConvertible, R1 : PerlScalarConvertible>(method: String, args: [PerlScalarConvertible?], context: PerlSub.ArrayContext = .array) throws -> (R0, R1)
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call<R0 : PerlScalarConvertible, R1 : PerlScalarConvertible>(method: PerlScalar, args: [PerlScalarConvertible?], context: PerlSub.ArrayContext = .array) throws -> (R0, R1)
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call<R0 : PerlScalarConvertible, R1 : PerlScalarConvertible>(method: String, _ args: PerlScalarConvertible?..., context: PerlSub.ArrayContext = .array) throws -> (R0, R1)
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call<R0 : PerlScalarConvertible, R1 : PerlScalarConvertible>(method: PerlScalar, _ args: PerlScalarConvertible?..., context: PerlSub.ArrayContext = .array) throws -> (R0, R1)
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call(method: PerlScalar, args: [PerlScalarConvertible?], context: PerlSub.ArrayContext) throws -> PerlSub.ReturnValues
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.
-
Calls the Perl method on the current instance.
The arguments of the call will be automagically converted to mortalized Perl scalar values with the lifetime of the scope of this call. The similar thing will happen to the Perl return values: they will be destroyed before the call returns (but after conversion to Swift values was done).
Declaration
Swift
public func call(method: PerlScalar, _ args: PerlScalarConvertible?..., context: PerlSub.ArrayContext) throws -> PerlSub.ReturnValues
Parameters
method
The name of the method to call.
args
Arguments to pass to the Perl method.
context
Context of the call.
Return Value
Values returned by the Perl method converted to requested Swift types.