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

Devel::Ladybug::Class::Dumper - Class and object introspection mix-in

PUBLIC CLASS MIX-IN METHODS

    * $class->members()

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

    * $class->membersHash()

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

    * $class->asserts()

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

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

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

    * $class->__baseAsserts()

    Returns a clone of the Devel::Ladybug::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 Devel::Ladybug::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 "YourApp::Example" => {
        #
        # Inherit parent class's base asserts, tack on "foo"
        #
        __baseAsserts => sub {
          my $class = shift;
    
          my $base = $class->SUPER::__baseAsserts();
    
          $base->{foo} = Devel::Ladybug::Str->assert();
    
          return $base;
        },
    
        # ...
      };

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

      create "YourApp::Example" => {
        #
        # Statically assert two base attributes, "id" and "name"
        #
        __baseAsserts => {
          id   => Devel::Ladybug::Int->assert(),
    
          name => Devel::Ladybug::Str->assert()
        },
    
        # ...
      }

    To inherit no base assertions:

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

    Overrides the abstract method from Devel::Ladybug::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 Devel::Ladybug.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 20:

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