HTML::Adsense - Create adsense widgets easily


HTML-Adsense documentation Contained in the HTML-Adsense distribution.

Index


Code Index:

NAME

Top

HTML::Adsense - Create adsense widgets easily

SYNOPSIS

Top

This module wraps Google Adsense ad creation in OO perl code.

  use HTML::Adsense;

  my $myad = HTML::Adsense->new(
    'client' => 'pub-4763368282156432',
  ); # OR
  $myad->client('pub-4763368282156432');
  print $myadd->render();

METHODS

Top

new

Creates the HTML::Adsense object.

render

Returns a the adsense code.

set_defaults

Sets several defaults, used in object creation.

set_format

Sets the height, width, type and format variables based on a format name and a list of preset values.

ACCESSOR METHODS

Top

client

The client ID.

width

The ad width.

height

The ad height.

format

The ad format.

type

The ad type.

channel

The ad channel.

border

The ad border color.

bg

The ad background color.

The ad link color.

text

The ad text color.

url

The ad url color.

SUPPORTED AD FORMATS

Top

This module has several height/width/type formats to select from. See the adsense formats page for more information on available adsense formats.

  https://www.google.com/adsense/adformats

This doesn't prevent you from using your own formats and colors. See the accessor methods for more information.

text 468x60
text 728x90

AUTHOR

Top

Nick Gerakines, <nick at gerakines.net>

CAVEATS

Top

[A] There is a default client ID set. You Must either pass the client ID when creating the object or set it via an accessor or you will NOT get paid.

[B] The current list of supported ad preset formats is very limited.

BUGS

Top

Please report any bugs or feature requests to bug-html-adsense at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-Adsense. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc HTML::Adsense

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/HTML-Adsense

* CPAN Ratings

http://cpanratings.perl.org/d/HTML-Adsense

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-Adsense

* Search CPAN

http://search.cpan.org/dist/HTML-Adsense

* Google Adsense Home Page

https://www.google.com/adsense/

* Google Adsense Blog

http://adsense.blogspot.com/

* Google Adsense Supported Formats

https://www.google.com/adsense/adformats

COPYRIGHT & LICENSE

Top


HTML-Adsense documentation Contained in the HTML-Adsense distribution.

package HTML::Adsense;

use strict;
use warnings;

use Class::Accessor;

use base qw(Class::Accessor);

HTML::Adsense->mk_accessors(qw(client width height format type channel border bg link text url));

our $VERSION = '0.2';

sub new {
	my ($class, %args) = @_;
	my $self = bless { %args }, $class;
	$self->set_defaults();
	return $self;
}

sub set_defaults {
	my ($self) = @_;
	$self->client('pub-4763368282156432');
	$self->set_format('text 468x60');
	$self->border('FFFFFF');
	$self->bg('FFFFFF');
	$self->link('CC6600');
	$self->text('000000');
	$self->url('008000');
	return 1;
}

sub set_format {
	my ($self, $format) = @_;

	my %formats = (
		'text 468x60' => ['468x60_as', 468, 60, 'text'],
		'text 728x90' => ['728x90_as', 728, 90, 'text'],
	);

	$format = $formats{$format} || $formats{'text 468x60'};
	$self->format($format->[0]);
	$self->width($format->[1]);
	$self->height($format->[2]);
	$self->type($format->[3]);

	return 1;
}

sub render {
	my ($self) = @_;
	
	if (! $self->client) { die 'A client ID must be provided.'; }
	
	my $ad = '';
	$ad .= <<'EOF';
<script type="text/javascript">
<!--
EOF

    for my $var (qw/client width height format type channel/) {
		if ( $self->$var ) { $ad .= "google_ad_$var = \"" . $self->$var . "\"\n"; }
	}
	
	for my $var (qw/border bg link text url/) {
		if ( $self->$var ) { $ad .= "google_color_$var = \"" . $self->$var . "\"\n"; }
	}

	$ad .= <<'EOF';
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
EOF

	return $ad;
}

1;