Acme-AsciiArtFarts

 view release on metacpan or  search on metacpan

lib/Acme/AsciiArtFarts.pm  view on Meta::CPAN

=head1 SYNOPSIS

This package provides a simple object orientated interface to AsciiArtFarts - a
website focussed on Ascii Art humour.

	use Acme::AsciiArtFarts;

	my $aaf = Acme::AsciiArtFarts->new();

	my $current = $aaf->current();
	print $current;

=head1 METHODS

=head2 new

Constructor - creates a new Acme:AsciiArtFarts object.  This method takes no arguments.

=cut

sub new {

lib/Acme/AsciiArtFarts.pm  view on Meta::CPAN

	$self->{req}	= HTTP::Request->new(GET => $self->{uri});
	$self->__get_keywords;
	$self->{cur_key}= '';
	$self->{cur_num}= 0;
	$self->{key_arr}= ();
	return $self
}

=head2 current

	print $aaf->current();

Returns the current strip.

=cut

sub current {
	return $_[0]->__request('/today.txt')
}

=head2 random

	print $aaf->random();

Returns a random strip.

=cut

sub random {
	return __parse($_[0]->__request('/random.cgi'));
}

=head2 list_keywords

	print join " ", $aaf->list_keywords();

Returns a list of all keywords by which strips are sorted.

=cut

sub list_keywords {
	return sort keys %{$_[0]->{keywords}}
}

=head2 list_by_keyword

lib/Acme/AsciiArtFarts.pm  view on Meta::CPAN

=cut

sub list_by_keyword {
	my ($self,$keyword)= @_;
	exists $self->{keywords}->{$keyword} or return 0;
	return @{$self->{keywords}{$keyword}{strips}};
}

=head2 get_by_num

	print $aaf->get_by_num($art[0]);

	print $aaf->get_by_num(int rand 1000);

Given a strip number as returned by other methods, return the requested strip.

Alternately, given an integer value that is a valid strip number, return the requested strip.

=cut

sub get_by_num {
	my ($self,$num)	=@_;
	$num	=~ /^#/	or $num = '#'.$num;

t/00-load.t  view on Meta::CPAN

#!perl -T

use Test::More tests => 1;

BEGIN {
    use_ok( 'Acme::AsciiArtFarts' ) || print "Bail out!
";
}

diag( "Testing Acme::AsciiArtFarts $Acme::AsciiArtFarts::VERSION, Perl $], $^X" );



( run in 2.124 seconds using v1.01-cache-2.11-cpan-de7293f3b23 )