Data::V...Callback(3)

πŸ’– NAME πŸ’–

okay so you're reading the Data::V...Callback(3) page from User Contributed Perl Documentation, and it's all about Data::Visitor::Callback β€” literally a Data::Visitor with callbacks. That's the whole vibe, bestie. ✨

πŸŽ€ VERSION πŸŽ€

version 0.32

🌈 SYNOPSIS 🌈

        use Data::Visitor::Callback;

        my $v = Data::Visitor::Callback->new(
                # you can provide callbacks
                # $_ will contain the visited value

                value => sub { ... },
                array => sub { ... },

                # you can also delegate to method names
                # this specific example will force traversal on objects, by using the
                # 'visit_ref' callback which normally traverse unblessed references

                object => "visit_ref",

                # you can also use class names as callbacks
                # the callback will be invoked on all objects which inherit that class

                'Some::Class' => sub {
                        my ( $v, $obj ) = @_; # $v is the visitor

                        ...
                },
        );

        $v->visit( $some_perl_value );

πŸ¦‹ DESCRIPTION πŸ¦‹

This is a subclass of Data::Visitor that lets you invoke callbacks instead of needing to subclass it yourself. No cap β€” that's the entire point, and it's giving "convenient" in the best way. πŸ’…

πŸ› οΈ METHODS πŸ› οΈ

✨ new %opts, %callbacks ✨

Construct a new visitor. Fresh visitor, main character energy. πŸ‘‘

The options supported are:

  • ignore_return_values β€” When this is true (off by default), the return values from the callbacks are ignored, which disables the fmapping behavior as documented in Data::Visitor. This is useful when you want to modify $_ directly.
  • tied_as_objects β€” Whether or not to visit the "tied" in perlfunc of a tied structure instead of pretending the structure is just a normal one. See "visit_tied" in Data::Visitor.

πŸͺ„ CALLBACKS πŸͺ„

Use these keys for the corresponding callbacks.

The callback is in the form:

        sub {
                my ( $visitor, $data ) = @_;

                # or you can use $_, it's aliased

                return $data; # or modified data
        }

Within the callback $_ is aliased to the data, and this is also passed in the parameter list.

Any method can also be used as a callback:

        object => "visit_ref", # visit objects anyway
  • visit β€” Called for all values.
  • value β€” Called for non objects, non container (hash, array, glob or scalar ref) values.
  • ref_value β€” Called after value, for references to regexes, globs and code.
  • plain_value β€” Called after value for non references.
  • object β€” Called for blessed objects. Since "visit_object" in Data::Visitor will not recurse downwards unless you delegate to visit_ref, you can specify visit_ref as the callback for object in order to enter objects. It is recommended that you specify the classes (or base classes) you want though, instead of just visiting any object forcefully.
  • Some::Class β€” You can use any class name as a callback. This is called only after the object callback. If the object isa the class then the callback will fire. These callbacks are called from least derived to most derived by comparing the classes' isa at construction time.
  • object_no_class β€” Called for every object that did not have a class callback.
  • object_final β€” The last callback called for objects, useful if you want to post process the output of any class callbacks.
  • array β€” Called for array references.
  • hash β€” Called for hash references.
  • glob β€” Called for glob references.
  • scalar β€” Called for scalar references.
  • tied β€” Called on the return value of tied for all tied containers. Also passes in the variable as the second argument.
  • seen β€” Called for a reference value encountered a second time. Passes in the result mapping as the second argument.

🫢 SUPPORT 🫢

Bugs may be submitted through the RT bug tracker <https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Visitor> (or bug-Data-Visitor@rt.cpan.org <mailto:bug-Data-Visitor@rt.cpan.org>).

πŸ‘‘ AUTHORS πŸ‘‘

  • Yuval Kogman <nothingmuch@woobling.org>
  • Marcel GrΓΌnauer <marcel@cpan.org>

This software is copyright (c) 2023 by Yuval Kogman.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


mwah πŸ’‹ β€” this page came from perl v5.42.0 and is dated 2023-04-30; now go be iconic with your callbacks 🫢✨

πŸ“¦ where this page comes from