1 #============================================================= -*-Perl-*-
6 # Visitor class for creating a view of all or part of a Pod Object
10 # Andy Wardley <abw@kfs.org>
13 # Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
15 # This module is free software; you can redistribute it and/or
16 # modify it under the same terms as Perl itself.
19 # $Id: View.pm 32 2009-03-17 21:08:25Z ford $
21 #========================================================================
23 package BASIS::Pod::POM::View;
28 use vars qw( $VERSION $DEBUG $ERROR $AUTOLOAD $INSTANCE );
30 $VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/);
31 $DEBUG = 0 unless defined $DEBUG;
34 #------------------------------------------------------------------------
36 #------------------------------------------------------------------------
40 my $args = ref $_[0] eq 'HASH' ? shift : { @_ };
41 bless { %$args }, $class;
46 my ($self, $item) = @_;
47 return UNIVERSAL::can($item, 'present')
48 ? $item->present($self) : $item;
53 my ($self, $type, $node) = @_;
60 my $class = ref $self || $self;
63 my $instance = \${"$class\::_instance"};
67 : ($$instance = $class->new(@_));
72 my ($self, $place) = @_;
73 $self = $self->instance() unless ref $self;
74 my $visit = $self->{ VISIT } ||= [ ];
75 push(@$visit, $place);
81 my ($self, $place) = @_;
82 $self = $self->instance() unless ref $self;
83 my $visit = $self->{ VISIT };
84 return $self->error('empty VISIT stack') unless @$visit;
90 my ($self, $place) = @_;
91 $self = $self->instance() unless ref $self;
92 my $visit = $self->{ VISIT };
93 return 0 unless $visit && @$visit;
95 foreach (reverse @$visit) {
96 return 1 if $_ eq $place;
104 my $name = $AUTOLOAD;
108 return if $name eq 'DESTROY';
110 if ($name =~ s/^view_//) {
111 return $self->view($name, @_);
113 elsif (! ref $self) {
114 die "can't access $name in $self\n";
117 die "no such method for $self: $name ($AUTOLOAD)"
118 unless defined ($item = $self->{ $name });
120 return wantarray ? ( ref $item eq 'ARRAY' ? @$item : $item ) : $item;
133 Visitor class for creating a view of all or part of a Pod Object Model.
157 Andy Wardley E<lt>abw@kfs.orgE<gt>
159 =head1 COPYRIGHT AND LICENSE
161 Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
163 This module is free software; you can redistribute it and/or
164 modify it under the same terms as Perl itself.