NAME

OP::Class::Dumper - Class and object introspection mix-in

PUBLIC CLASS MIX-IN METHODS

* $class->members()

Return an OP::Array containing the names of all valid messages (symbols) in this class.

* $class->membersHash()

Return an OP::Hash containing the CODE refs of all valid messages in this class, keyed on message (symbol) name.

* $class->asserts()

Returns the OP::Hash of attribute assertions for this class, including any base assertions which may be present.

Overrides the abstract method from OP::Class with a concrete implementation for non-abstract classes.

my $asserts = $class->asserts();

* $class->__baseAsserts()

Returns a clone of the OP::Hash of base assertions for this class. Types are not inherited by subclasses, unless defined in the hash returned by this method. Override in subclass to provide a hash of inherited assertions.

Unless implementing a new abstract class that uses special keys, __baseAsserts() does not need to be used or modified. Concrete classes should just use inline assertions as per the examples in OP::Type.

__baseAsserts() may be overridden as a sub{} or as a class variable.

Using a sub{} lets you extend the parent class's base asserts, or use any other Perl operation to derive the appropriate values:

create "OP::Example" => {
  #
  # Inherit parent class's base asserts, tack on "foo"
  #
  __baseAsserts => method(OP::Class $class:) {
    my $base = $class->SUPER::__baseAsserts();

    $base->{foo} = OP::Str->assert();

    return $base;
  },

  # ...
};

One may alternately use a class variable to redefine base asserts, overriding the parent:

create "OP::Example" => {
  #
  # Statically assert two base attributes, "id" and "name"
  #
  __baseAsserts => {
    id   => OP::Int->assert(),

    name => OP::Str->assert()
  },

  # ...
}

To inherit no base assertions:

create "OP::RebelExample" => {
  #
  # Sometimes, parent doesn't know best:
  #
  __baseAsserts => { },

  # ...
}

Overrides the abstract method from OP::Class with a concrete implementation for non-abstract classes.

PUBLIC INSTANCE MIX-IN METHODS

  • $self->sprint(), $self->toYaml()

    Object introspection method.

    Returns a string containing a YAML representation of the current object.

    $r->content_type('text/plain');
    
    $r->print($object->toYaml());
  • $self->print()

    Prints a YAML representation of the current object to STDOUT.

  • $self->prettySprint();

    Returns a nicely formatted string representing the contents of self

  • $self->prettyPrint();

    Prints a nicely formatted string representing self to STDOUT

SEE ALSO

This file is part of OP.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 19:

You can't have =items (as at line 39) unless the first thing after the =over is an =item