Class-Visitor

 view release on metacpan or  search on metacpan

Visitor.pm  view on Meta::CPAN

  $value = $obj->pop_ARRAYMEMBER;
  $obj->as_string ([$context[, ...]]);
  $obj->ARRAYMEMBER_as_string ([$context[, ...]]);

  $iter inherits the following from Class::Iter:

  $iter->parent;
  $iter->is_iter;
  $iter->root;
  $iter->rootpath;
  $iter->next;
  $iter->at_end;
  $iter->delegate;
  $iter->is_same ($obj);

=head1 DESCRIPTION

C<Class::Visitor> extends the getter/setter functions provided by
C<Class::Template> for I<CLASS> by defining methods for using the
Visitor and Iterator design patterns.  All of the Iterator methods are
inherited from C<Class::Iter> except C<iter>.

I<CLASS> is the name of the new class, I<SUPER> the superclass of
this class (will define C<@ISA>), and I<TEMPLATE> is as defined in
C<Class::Template>.

C<$obj->iter> returns a new iterator for this object.  If C<parent>,
C<array>, and C<index> are not defined, then the new iterator is
treated as the root object.  Except as inherited from C<Class::Iter>
or as defined below, methods for C<$iter> and C<$obj> work the same.

The C<accept> methods cause a callback to C<$visitor> with C<$self> as
the first argument plus the rest of the arguments passed to
C<accept>.  This is implemented like:

    sub accept {
        my $self = shift; my $visitor = shift;
        $visitor->visit_MyClass ($self, @_);
    }

C<children_accept> calls C<accept> on each object in the array field
named C<contents>.  C<children_accept_I<ARRAYMEMBER>> does the same for
I<ARRAYMEMBER>.

Calling C<accept> methods on iterators always calls back using
iterators.  Calling C<accept> on non-iterators calls back using
non-iterators.  The latter is significantly faster.

C<push> and C<pop> act like their respective array functions.

C<as_string> returns the concatenated scalar values of the array field
named C<contents>, possibly modified by C<$context>.
C<I<ARRAYMEMBER>_as_string> does the same for I<ARRAYMEMBER>.

Visitor handles scalars specially for C<children_accept> and
C<as_string>.  In the case of C<children_accept>, Visitor will create
an iterator in the class C<Class::Scalar::Iter> with the scalar as the
delegate.

In the case of C<as_string>, Visitor will use the string unless
C<$context-E<gt>{cdata_mapper}> is defined, in which case it returns
the result of calling the C<cdata_mapper> subroutine with the scalar
and the remaining arguments.  The actual implementation is:

    &{$context->{cdata_mapper}} ($scalar, @_);

=head1 AUTHOR

Ken MacLeod, ken@bitsko.slc.ut.us

=head1 SEE ALSO

perl(1), Class::Template(3), Class::Iter(3).

The package C<SGML::SPGrove> uses C<Class::Visitor> extensively.

=cut



( run in 0.832 second using v1.01-cache-2.11-cpan-6aa56a78535 )