[Catalyst-commits] r7898 - in trunk: . Catalyst-Model-Akismet
Catalyst-Model-Akismet/lib Catalyst-Model-Akismet/lib/Catalyst
Catalyst-Model-Akismet/lib/Catalyst/Helper
Catalyst-Model-Akismet/lib/Catalyst/Helper/Model
Catalyst-Model-Akismet/lib/Catalyst/Model
Catalyst-Model-Akismet/t Catalyst-Model-Akismet/t/lib
Catalyst-Model-Akismet/t/lib/TestApp
Catalyst-Model-Akismet/t/lib/TestApp/Model
marcus at dev.catalyst.perl.org
marcus at dev.catalyst.perl.org
Fri Jun 6 10:01:38 BST 2008
Author: marcus
Date: 2008-06-06 10:01:37 +0100 (Fri, 06 Jun 2008)
New Revision: 7898
Added:
trunk/Catalyst-Model-Akismet/
trunk/Catalyst-Model-Akismet/Changes
trunk/Catalyst-Model-Akismet/INSTALL
trunk/Catalyst-Model-Akismet/MANIFEST
trunk/Catalyst-Model-Akismet/META.yml
trunk/Catalyst-Model-Akismet/Makefile.PL
trunk/Catalyst-Model-Akismet/lib/
trunk/Catalyst-Model-Akismet/lib/Catalyst/
trunk/Catalyst-Model-Akismet/lib/Catalyst/Helper/
trunk/Catalyst-Model-Akismet/lib/Catalyst/Helper/Model/
trunk/Catalyst-Model-Akismet/lib/Catalyst/Helper/Model/Akismet.pm
trunk/Catalyst-Model-Akismet/lib/Catalyst/Model/
trunk/Catalyst-Model-Akismet/lib/Catalyst/Model/Akismet.pm
trunk/Catalyst-Model-Akismet/t/
trunk/Catalyst-Model-Akismet/t/00.load.t
trunk/Catalyst-Model-Akismet/t/01.functionality.t
trunk/Catalyst-Model-Akismet/t/02.perlcritic.t
trunk/Catalyst-Model-Akismet/t/03.pod.t
trunk/Catalyst-Model-Akismet/t/04.pod-coverage.t
trunk/Catalyst-Model-Akismet/t/lib/
trunk/Catalyst-Model-Akismet/t/lib/TestApp.pm
trunk/Catalyst-Model-Akismet/t/lib/TestApp/
trunk/Catalyst-Model-Akismet/t/lib/TestApp/Model/
trunk/Catalyst-Model-Akismet/t/lib/TestApp/Model/Akismet.pm
Log:
new model for Akismet antispam protocol
Added: trunk/Catalyst-Model-Akismet/Changes
===================================================================
--- trunk/Catalyst-Model-Akismet/Changes (rev 0)
+++ trunk/Catalyst-Model-Akismet/Changes 2008-06-06 09:01:37 UTC (rev 7898)
@@ -0,0 +1,4 @@
+Revision history for Catalyst::Model::Akismet
+
+0.01 2007-03-07:
+ Initial release. Based on S3 Model
Added: trunk/Catalyst-Model-Akismet/INSTALL
===================================================================
--- trunk/Catalyst-Model-Akismet/INSTALL (rev 0)
+++ trunk/Catalyst-Model-Akismet/INSTALL 2008-06-06 09:01:37 UTC (rev 7898)
@@ -0,0 +1,13 @@
+To install this module, run the following commands...
+
+ perl Makefile.PL
+ make
+ make test
+ make install
+
+Alternatively, to install with Module::Build...
+
+ perl Build.PL
+ ./Build
+ ./Build test
+ ./Build install
Added: trunk/Catalyst-Model-Akismet/MANIFEST
===================================================================
--- trunk/Catalyst-Model-Akismet/MANIFEST (rev 0)
+++ trunk/Catalyst-Model-Akismet/MANIFEST 2008-06-06 09:01:37 UTC (rev 7898)
@@ -0,0 +1,22 @@
+Changes
+inc/Module/Install.pm
+inc/Module/Install/Base.pm
+inc/Module/Install/Can.pm
+inc/Module/Install/Fetch.pm
+inc/Module/Install/Makefile.pm
+inc/Module/Install/Metadata.pm
+inc/Module/Install/Win32.pm
+inc/Module/Install/WriteAll.pm
+INSTALL
+lib/Catalyst/Helper/Model/Akismet.pm
+lib/Catalyst/Model/Akismet.pm
+Makefile.PL
+MANIFEST This list of files
+META.yml
+t/00.load.t
+t/01.functionality.t
+t/02.perlcritic.t
+t/03.pod.t
+t/04.pod-coverage.t
+t/lib/TestApp.pm
+t/lib/TestApp/Model/Akismet.pm
Added: trunk/Catalyst-Model-Akismet/META.yml
===================================================================
--- trunk/Catalyst-Model-Akismet/META.yml (rev 0)
+++ trunk/Catalyst-Model-Akismet/META.yml 2008-06-06 09:01:37 UTC (rev 7898)
@@ -0,0 +1,23 @@
+---
+abstract: 'Catalyst model for the Akismet anti-spam protocol'
+author:
+ - 'Marcus Ramberg <mramberg at cpan.org'
+build_requires:
+ Test::More: 0
+distribution_type: module
+generated_by: 'Module::Install version 0.72'
+license: perl
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.3.html
+ version: 1.3
+name: Catalyst-Model-Akismet
+no_index:
+ directory:
+ - inc
+ - t
+requires:
+ Carp: 0
+ Catalyst::Component::InstancePerContext: 0
+ Catalyst::Runtime: 5.70
+ Net::Akismet::Protocol: 0
+version: 0.01
Added: trunk/Catalyst-Model-Akismet/Makefile.PL
===================================================================
--- trunk/Catalyst-Model-Akismet/Makefile.PL (rev 0)
+++ trunk/Catalyst-Model-Akismet/Makefile.PL 2008-06-06 09:01:37 UTC (rev 7898)
@@ -0,0 +1,16 @@
+use strict;
+use warnings;
+use inc::Module::Install 0.65;
+
+name 'Catalyst-Model-Akismet';
+all_from 'lib/Catalyst/Model/Akismet.pm';
+license 'perl';
+
+build_requires 'Test::More';
+
+requires 'Carp';
+requires 'Catalyst::Runtime' => '5.70';
+requires 'Catalyst::Component::InstancePerContext';
+requires 'Net::Akismet::Protocol';
+
+WriteAll;
Added: trunk/Catalyst-Model-Akismet/lib/Catalyst/Helper/Model/Akismet.pm
===================================================================
--- trunk/Catalyst-Model-Akismet/lib/Catalyst/Helper/Model/Akismet.pm (rev 0)
+++ trunk/Catalyst-Model-Akismet/lib/Catalyst/Helper/Model/Akismet.pm 2008-06-06 09:01:37 UTC (rev 7898)
@@ -0,0 +1,171 @@
+package Catalyst::Helper::Model::Akismet;
+
+use strict;
+use warnings;
+
+use Carp qw( croak );
+
+our $VERSION = '0.01';
+
+
+=head1 NAME
+
+Catalyst::Helper::Model::Akismet - Helper for Akismet Catalyst models
+
+=head1 SYNOPSIS
+
+ script/myapp_create.pl model ModelName Akismet [ key=your_key url=your url ]
+
+
+=head1 DESCRIPTION
+
+Use this module to set up a new L<Catalyst::Model::S3> model for your Catalyst
+application.
+
+=head2 Arguments
+
+ ModelName is the short name for the Model class being generated (eg. "S3")
+
+ key and secret correspond to your Amazon Web Services account's Access Key
+ ID and Secret Access Key respectively. For more information see:
+ L<http://aws.amazon.com/s3>
+
+ The presence of secure indicates that your Model should use SSL-encrypted
+ connections when talking to S3.
+
+ Explicitly setting timeout (in seconds) overrides the default of 30.
+
+
+=head1 METHODS
+
+=head2 mk_compclass
+
+This method takes the given arguments and generates a Catalyst::Model::S3
+model for your application.
+
+=cut
+
+sub mk_compclass {
+ my ( $self, $helper, @options ) = @_;
+
+ # Extract the arguments...
+ foreach (@options) {
+ if ( /^key=(.+)$/ ) {
+ $helper->{key} = $1;
+ }
+ elsif ( /^url=(.+)$/ ) {
+ $helper->{url} = $1;
+ }
+ }
+
+ $helper->{config_encountered} = (
+ exists $helper->{key}
+ || exists $helper->{url}
+ );
+
+ $helper->render_file( 'akismetclass', $helper->{file} );
+}
+
+
+=head1 SEE ALSO
+
+L<Catalyst>, L<Catalyst::Helper>, L<Catalyst::Model::Akismet>
+
+
+=head1 BUGS
+
+Please report any bugs or feature requests to
+C<bug-catalyst-model-s3 at rt.cpan.org>, or through the web interface at
+L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Model-S3>.
+
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+ perldoc Catalyst::Helper::Model::Akismet
+
+You may also look for information at:
+
+=over 4
+
+=item * L<Catalyst::Model::Akismet>
+
+=item * AnnoCPAN: Annotated CPAN documentation
+
+L<http://annocpan.org/dist/Catalyst-Model-S3/>
+
+=item * RT: CPAN's request tracker
+
+L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Model-S3>
+
+=item * Search CPAN
+
+L<http://search.cpan.org/dist/Catalyst-Model-S3/>
+
+=back
+
+=head1 AUTHOR
+
+Marcus Ramberg <mramberg at cpan.org
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (c) 2008 Marcus Ramberg
+
+This module is free software; you can redistribute it and/or modify it under
+the same terms as Perl itself. See L<perlartistic>.
+
+=cut
+
+
+1;
+__DATA__
+=begin pod_to_ignore
+
+__akismetclass__
+package [% class %];
+
+use strict;
+use warnings;
+
+use base qw/ Catalyst::Model::Akismet /;
+
+[%- IF config_encountered %]
+__PACKAGE__->config(
+ [% "aksimet_key => '" _ aksimet_key _ "',\n" IF aksimet_key -%]
+ [% "akismet_url => '" _ akismet_url _ "',\n" IF akismet_url -%]
+ [% "akismet_host => '" _ akismet_host _ "',\n" IF akismet_host -%]
+
+);
+[%- END %]
+
+
+=head1 NAME
+
+[% class %] - Akismet Model Class
+
+=head1 SYNOPSIS
+
+See L<[% app %]>.
+
+
+=head1 DESCRIPTION
+
+S3 Model Class.
+
+
+=head1 AUTHOR
+
+[% author %]
+
+
+=head1 LICENSE
+
+This module is free software; you can redistribute it and/or modify it under
+the same terms as Perl itself. See L<perlartistic>.
+
+=cut
+
+
+1;
Added: trunk/Catalyst-Model-Akismet/lib/Catalyst/Model/Akismet.pm
===================================================================
--- trunk/Catalyst-Model-Akismet/lib/Catalyst/Model/Akismet.pm (rev 0)
+++ trunk/Catalyst-Model-Akismet/lib/Catalyst/Model/Akismet.pm 2008-06-06 09:01:37 UTC (rev 7898)
@@ -0,0 +1,173 @@
+package Catalyst::Model::Akismet;
+
+use strict;
+use warnings;
+
+use base qw/Catalyst::Component::InstancePerContext Catalyst::Model/;
+
+use Carp qw( croak );
+use Catalyst::Utils ();
+use Net::Akismet::Protocol ();
+use Class::C3();
+our $VERSION = '0.01';
+
+
+=head1 NAME
+
+Catalyst::Model::Akismet - Catalyst model for the Akismet anti-spam protocol
+
+=head1 SYNOPSIS
+
+ # Use the helper to add an Akismet model to your application...
+ script/myapp_create.pl create model Akismet Akismet
+
+
+ # lib/MyApp/Model/Akismet.pm
+
+ package MyApp::Model::Akismet;
+
+ use base qw/ Catalyst::Model::Akismet /;
+
+ __PACKAGE__->config(
+ url => 'http://yourblog.com',
+ key => 'SECRET',
+ host => 'rest.akismet.net'
+ );
+
+ 1;
+
+
+ # In a controller...
+ my $akismet = $c->model('Akismet');
+ print ref($akismet); # Net::Amazon::Akismet
+
+
+=head1 DESCRIPTION
+
+This is a L<Catalyst> model class that interfaces with the Akismet anti-
+spam protocol. By default it will connect to typepad's antispam service.
+
+=head1 METHODS
+
+=head2 ->new()
+
+Instantiate a new L<Net::Amazon::Akismet> Model. See
+L<Net::Akismet::Protocols's new method|Net::Akismet::Protocol/new> for the options available.
+
+
+=head2 check
+
+Check if a comment is spam. Sets user_ip, user_agent and referer and proxies to
+L<Net::Akismet::Protocol>'s check method. See that method for more info about parameters.
+
+=cut
+
+sub new {
+ my $self = shift->next::method(@_);
+ my $class = ref($self);
+
+ my ( $c, $arg_ref ) = @_;
+
+ # Ensure that the required configuration is available...
+ croak "->config->{key} must be set for $class\n"
+ unless $self->{key};
+ croak "->config->{url} must be set for $class\n"
+ unless $self->{url};
+
+ # Instantiate a new Akismet object...
+ $self->{'akismet'} = Net::Akismet::Protocol->new(
+ Catalyst::Utils::merge_hashes( $arg_ref, $self->config )
+ );
+
+ return $self;
+}
+
+
+sub check {
+ my ($self,%params)=@_;
+ return $self->{akismet}->check(
+ %params,%{$self->{params}} )
+}
+
+sub akismet {
+ my $self=shift;
+ return $self->{akismet};
+}
+
+sub build_per_context_instance {
+my ($self, $c) = @_;
+
+ return $self unless ref $c;
+ $self->{params}= {
+ user_ip => $c->req->address,
+ user_agent => $c->req->user_agent,
+ referer => $c->req->referer,
+ };
+
+ return $self;
+}
+
+1; # End of the module code; everything from here is documentation...
+__END__
+
+=head2 build_per_context_instance
+
+=head2 akismet
+
+Access the L<Net::Akismet::Protocol> object directly.
+
+Gets info about user. Called by Catalyst automatically.
+
+=head1 SEE ALSO
+
+L<Catalyst>, L<Catalyst::Helper::Model::Akismet>, L<Net::Akismet::Protocol>
+
+=head1 BUGS
+
+Please report any bugs or feature requests to
+C<bug-catalyst-model-akismet at rt.cpan.org>, or through the web interface at
+L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Model-Akismet>.
+
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+ perldoc Catalyst::Model::Akismet
+
+You may also look for information at:
+
+=over 4
+
+=item * Catalyst::Model::Akismet
+
+L<http://perlprogrammer.co.uk/modules/Catalyst::Model::S3/>
+
+=item * AnnoCPAN: Annotated CPAN documentation
+
+L<http://annocpan.org/dist/Catalyst-Model-Akismet/>
+
+=item * RT: CPAN's request tracker
+
+L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Model-Akismet>
+
+=item * Search CPAN
+
+L<http://search.cpan.org/dist/Catalyst-Model-Akismet/>
+
+=back
+
+
+=head1 AUTHOR
+
+Marcus Ramberg <mramberg at cpan.org
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (c) 2008 Marcus Ramberg.
+
+This module is free software; you can redistribute it and/or modify it under
+the same terms as Perl itself. See L<perlartistic>.
+
+
+=cut
Added: trunk/Catalyst-Model-Akismet/t/00.load.t
===================================================================
--- trunk/Catalyst-Model-Akismet/t/00.load.t (rev 0)
+++ trunk/Catalyst-Model-Akismet/t/00.load.t 2008-06-06 09:01:37 UTC (rev 7898)
@@ -0,0 +1,11 @@
+#!perl -wT
+
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+
+use_ok( 'Catalyst::Model::Akismet' );
+
+diag( 'Testing Catalyst::Model::Akismet '
+ . $Catalyst::Model::Akismet::VERSION );
Added: trunk/Catalyst-Model-Akismet/t/01.functionality.t
===================================================================
--- trunk/Catalyst-Model-Akismet/t/01.functionality.t (rev 0)
+++ trunk/Catalyst-Model-Akismet/t/01.functionality.t 2008-06-06 09:01:37 UTC (rev 7898)
@@ -0,0 +1,19 @@
+#!/usr/bin/perl -wT
+
+use strict;
+use warnings;
+
+use Test::More tests => 3;
+use lib qw( t/lib );
+
+
+# Make sure the Catalyst app loads ok...
+use_ok('TestApp');
+
+
+my $amazon = TestApp->model('Akismet');
+isa_ok( $amazon, 'Catalyst::Model::Akismet' );
+can_ok( $amazon, 'akismet' );
+
+
+1;
Added: trunk/Catalyst-Model-Akismet/t/02.perlcritic.t
===================================================================
--- trunk/Catalyst-Model-Akismet/t/02.perlcritic.t (rev 0)
+++ trunk/Catalyst-Model-Akismet/t/02.perlcritic.t 2008-06-06 09:01:37 UTC (rev 7898)
@@ -0,0 +1,15 @@
+#!perl -wT
+
+use strict;
+use warnings;
+
+use Test::More;
+
+
+eval 'use Test::Perl::Critic';
+if ( $@ ) {
+ plan skip_all => 'Test::Perl::Critic required to test for best-practices';
+}
+else {
+ Test::Perl::Critic::all_critic_ok();
+}
Added: trunk/Catalyst-Model-Akismet/t/03.pod.t
===================================================================
--- trunk/Catalyst-Model-Akismet/t/03.pod.t (rev 0)
+++ trunk/Catalyst-Model-Akismet/t/03.pod.t 2008-06-06 09:01:37 UTC (rev 7898)
@@ -0,0 +1,15 @@
+#!perl -wT
+
+use strict;
+use warnings;
+
+use Test::More;
+
+
+eval 'use Test::Pod 1.14';
+if ( $@ ) {
+ plan skip_all => 'Test::Pod 1.14 required for testing POD';
+}
+else {
+ Test::Pod::all_pod_files_ok();
+}
Added: trunk/Catalyst-Model-Akismet/t/04.pod-coverage.t
===================================================================
--- trunk/Catalyst-Model-Akismet/t/04.pod-coverage.t (rev 0)
+++ trunk/Catalyst-Model-Akismet/t/04.pod-coverage.t 2008-06-06 09:01:37 UTC (rev 7898)
@@ -0,0 +1,15 @@
+#!perl -wT
+
+use strict;
+use warnings;
+
+use Test::More;
+
+
+eval 'use Test::Pod::Coverage 1.04';
+if ( $@ ) {
+ plan skip_all => 'Test::Pod::Coverage 1.04 required for testing POD coverage';
+}
+else {
+ Test::Pod::Coverage::all_pod_coverage_ok();
+}
Added: trunk/Catalyst-Model-Akismet/t/lib/TestApp/Model/Akismet.pm
===================================================================
--- trunk/Catalyst-Model-Akismet/t/lib/TestApp/Model/Akismet.pm (rev 0)
+++ trunk/Catalyst-Model-Akismet/t/lib/TestApp/Model/Akismet.pm 2008-06-06 09:01:37 UTC (rev 7898)
@@ -0,0 +1,7 @@
+package # hide from PAUSE
+ TestApp::Model::Akismet;
+
+use base qw/ Catalyst::Model::Akismet /;
+
+
+1;
Added: trunk/Catalyst-Model-Akismet/t/lib/TestApp.pm
===================================================================
--- trunk/Catalyst-Model-Akismet/t/lib/TestApp.pm (rev 0)
+++ trunk/Catalyst-Model-Akismet/t/lib/TestApp.pm 2008-06-06 09:01:37 UTC (rev 7898)
@@ -0,0 +1,20 @@
+package # hide from PAUSE
+ TestApp;
+
+use strict;
+use warnings;
+
+use Catalyst;
+
+__PACKAGE__->config(
+ name => 'TestApp',
+ 'Model::Akismet' => {
+ key => 'fake key',
+ url => 'http://fake_url',
+ },
+);
+
+__PACKAGE__->setup;
+
+
+1;
More information about the Catalyst-commits
mailing list