ASP-NextLink

 view release on metacpan or  search on metacpan

NextLink.pm  view on Meta::CPAN

#
#####################################################################
package ASP::NextLink;

use strict;
use CGI::Carp;
use vars qw( $VERSION );

$VERSION = '0.11';

sub new {
	my $class = shift;
	die "Cannot call class method on an object" if ref $class;
	my $linkfile = $main::Server->MapPath( shift );
	my $self = {};
	bless $self, $class;
	$self->parse_linkfile( $linkfile );
	$self;
}

sub parse_linkfile {
	my ($self, $linkfile, $idx) = (shift, shift, 0);
	die "Cannot call object method on class"  unless ref $self;
	open LNX, "<$linkfile" or die "Can't open $linkfile: $!\n";
	while ( <LNX> ) {
		chomp;
		if ( /^([^\t]+)\t([^\t]+)\t?.*$/ ) {
			$idx++;
			$self->{_url}{$main::Server->MapPath($1)} = $idx;
			$self->{_idx}{$idx} = [ $1, $2 ];
		}

NextLink.pm  view on Meta::CPAN


=head2 GetListCount()

Returns the number of links (lines containing tab-separated fields)
in link file.

	my $count = $nl->GetListCount();

=cut

sub GetListCount {
	my $self = shift;
	die "Cannot call object method on class"  unless ref $self;
	$self->{_count};
}

=head2 GetListIndex()

Index of the current page in the link file.

=cut

sub GetListIndex {
	my $self = shift;
	die "Cannot call object method on class"  unless ref $self;
	$self->{_url}{$ENV{SCRIPT_FILENAME}}
		or die "Current page not found in $self->{_file}";
}

=head2 GetPreviousURL()

URL of the previous page in the link file.

=cut

sub GetPreviousURL {
	my $self = shift;
	die "Cannot call object method on class"  unless ref $self;
	my $idx = $self->GetListIndex - 1;
	exists( $self->{_idx}{$idx} )
		? $self->{_idx}{$idx}[0] : undef;
}

=head2 GetPreviousDescription()

Description of the previous page in the link file.

=cut

sub GetPreviousDescription {
	my $self = shift;
	die "Cannot call object method on class"  unless ref $self;
	my $idx = $self->GetListIndex - 1;
	exists( $self->{_idx}{$idx} )
		? $self->{_idx}{$idx}[1] : undef;
}

=head2 GetNextURL()

URL of the next page in the link file.

=cut

sub GetNextURL {
	my $self = shift;
	die "Cannot call object method on class"  unless ref $self;
	my $idx = $self->GetListIndex + 1;
	exists( $self->{_idx}{$idx} )
		? $self->{_idx}{$idx}[1] : undef;
}

=head2 GetNextDescription()

Description of the next page in the link file.

=cut

sub GetNextDescription {
	my $self = shift;
	die "Cannot call object method on class"  unless ref $self;
	my $idx = $self->GetListIndex + 1;
	exists( $self->{_idx}{$idx} )
		? $self->{_idx}{$idx}[1] : undef;
}

=head2 GetNthURL( n )

URL of the nth page in the link file.
NOTE: Index is 1-based, NOT zero-based.

=cut

sub GetNthURL {
	my $self = shift;
	die "Cannot call object method on class"  unless ref $self;
	my $idx = shift;
	$self->{_idx}{$idx}[0];
}

=head2 GetNthDescription( n )

Description of the nth page in the link file.
NOTE: Index is 1-based, NOT zero-based.

=cut

sub GetNthDescription {
	my $self = shift;
	die "Cannot call object method on class"  unless ref $self;
	my $idx = shift;
	$self->{_idx}{$idx}[1];
}

=head1 AUTHOR

Tim Hammerquist E<lt>F<cafall@voffice.net>E<gt>



( run in 0.258 second using v1.01-cache-2.11-cpan-4d50c553e7e )