The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

OP::Scalar - Scalar object class

DESCRIPTION

Extends OP::Object to handle Perl scalar values as OP Objects.

INHERITANCE

This class inherits additional class and object methods from the following packages:

OP::Class > OP::Object > OP::Scalar

SYNOPSIS

  use OP::Scalar;

  {
    my $scalar = OP::Scalar->new("Hello World");
    print "$scalar\n";

    # Hello World
  }

  {
    my $scalar = OP::Scalar->new(5);
    my $result = $scalar + $scalar;
    print "$scalar + $scalar = $result\n";

    # 5 + 5 = 10
  }

PUBLIC CLASS METHODS

  • $class->new($scalar)

    Instantiate a new OP::Scalar. Accepts an optional scalar value as a prototype object

    Usage is cited in the SYNOPSIS section of this document.

PUBLIC INSTANCE METHODS

  • $self->get()

    Abstract method, not implemented.

    Delegates to superclass if class method.

  • $self->set( )

    Abstract method, not implemented.

    Delegates to superclass if class method.

  • $self->size()

    Object wrapper for Perl's built-in length() function. Functionally the same as length(@$ref).

      my $scalar = OP::Scalar->new("Testing");
    
      my $size = $scalar->size(); # returns 7
  • $self->isEmpty()

    Returns a true value if self contains no values, otherwise false.

      my $array = OP::Scalar->new("");
    
      if ( $self->isEmpty() ) {
        print "Is Empty\n";
      }
    
      # Expected Output:
      #
      # Is Empty
      #
  • $self->clear()

    Truncate self to zero length.

  • $self->value()

    Returns the actual de-referenced value of self. Same as ${ $self };

  • $self->sprint()

    Overrides superclass to sprint the actual de-referenced value of self.

  • $self->say()

    Prints the de-referenced value of self with a line break at the end.

SEE ALSO

perlfunc

This file is part of OP.

REVISION

$Id: $