Commits

Toby Inkster  committed 48d630c

initial commit

  • Participants

Comments (0)

Files changed (11)

+use inc::Module::Package 'RDF 0.009';
+

File lib/MooseX/DeclareX/Plugin/singleton.pm

+package MooseX::DeclareX::Plugin::singleton;
+
+BEGIN {
+	$MooseX::DeclareX::Plugin::singleton::AUTHORITY = 'cpan:TOBYINK';
+	$MooseX::DeclareX::Plugin::singleton::VERSION   = '0.001';
+}
+
+use Moose;
+with 'MooseX::DeclareX::Plugin';
+
+use MooseX::Declare 0 ();
+use Moose::Util ();
+use MooseX::Singleton::Role::Object 0 ();
+
+sub _callback
+{
+	my $caller = shift;
+	
+	Moose::Util::MetaRole::apply_metaroles(
+		for   => $caller,
+		class_metaroles => {
+			class       => ['MooseX::Singleton::Role::Meta::Class'],
+			instance    => ['MooseX::Singleton::Role::Meta::Instance'],
+			constructor => ['MooseX::Singleton::Role::Meta::Method::Constructor'],
+		},
+	);
+	Moose::Util::MetaRole::apply_base_class_roles(
+		for   => $caller,
+		roles => ['MooseX::Singleton::Role::Object'],
+	);
+}
+
+sub plugin_setup
+{
+	my ($class, $kw) = @_;
+
+	if ($kw->isa('MooseX::DeclareX::Keyword::class'))
+	{
+		$kw->register_feature(singleton => sub {
+			my ($self, $ctx, $package) = @_;
+			$ctx->add_early_cleanup_code_parts(
+				"MooseX::DeclareX::Plugin::singleton::_callback(q[$package])"
+			);
+		});
+	}
+}
+
+1;
+
+
+__END__
+
+=head1 NAME
+
+MooseX::DeclareX::Plugin::singleton - shiny syntax for MooseX::Singleton
+
+=head1 SYNOPSIS
+
+ class Logger is singleton
+ {
+    method log ($str) {
+       ...;
+    }
+ }
+ 
+ Logger->instance->log("here we are!");
+
+=head1 DESCRIPTION
+
+This distribution extends MooseX::DeclareX with a new plugin:
+
+=over
+
+=item C<< is singleton >>
+
+Marks a class as a singleton, providing C<< instance >> and C<< initialize >>
+methods as per L<MooseX::Singleton>.
+
+=back
+
+=head1 BUGS
+
+B<Known issue:> you may occasionally get errors about inlining the constructor.
+
+Please report any bugs to
+L<http://rt.cpan.org/Dist/Display.html?Queue=MooseX-DeclareX-Plugin-singleton>.
+
+=head1 SEE ALSO
+
+L<MooseX::DeclareX>, L<MooseX::Singleton>.
+
+=head1 AUTHOR
+
+Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
+
+=head1 COPYRIGHT AND LICENCE
+
+This software is copyright (c) 2012 by Toby Inkster.
+
+This is free software; you can redistribute it and/or modify it under
+the same terms as the Perl 5 programming language system itself.
+
+=head1 DISCLAIMER OF WARRANTIES
+
+THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+

File meta/changes.pret

+# This file acts as the project's changelog.
+
+`MooseX-DeclareX-Plugin-singleton 0.001 cpan:TOBYINK`
+	issued  2012-08-23;
+	label   "Initial release".
+

File meta/doap.pret

+# This file contains general metadata about the project.
+
+@prefix : <http://usefulinc.com/ns/doap#>.
+
+`MooseX-DeclareX-Plugin-singleton`
+	:programming-language "Perl" ;
+	:shortdesc            "shiny syntax for MooseX::Singleton";
+	:homepage             <https://metacpan.org/release/MooseX-DeclareX-Plugin-singleton>;
+	:download-page        <https://metacpan.org/release/MooseX-DeclareX-Plugin-singleton>;
+	:bug-database         <http://rt.cpan.org/Dist/Display.html?Queue=MooseX-DeclareX-Plugin-singleton>;
+	:created              2012-08-23;
+	:license              <http://dev.perl.org/licenses/>;
+	:maintainer           cpan:TOBYINK;
+	:developer            cpan:TOBYINK.
+
+<http://dev.perl.org/licenses/>
+	dc:title  "the same terms as the perl 5 programming language system itself".
+
+cpan:TOBYINK
+	foaf:name  "Toby Inkster";
+	foaf:mbox  <mailto:tobyink@cpan.org>.
+

File meta/makefile.pret

+# This file provides instructions for packaging.
+
+`MooseX-DeclareX-Plugin-singleton`
+	perl_version_from m`MooseX::DeclareX::Plugin::singleton`;
+	version_from      m`MooseX::DeclareX::Plugin::singleton`;
+	readme_from       m`MooseX::DeclareX::Plugin::singleton`;
+	test_requires     p`Test::More 0.61`  .
+
+use Test::More tests => 1;
+BEGIN { use_ok('MooseX::DeclareX::Plugin::singleton') };
+

File t/02singletons.t

+use Test::More tests => 4;
+use MooseX::DeclareX
+	plugins => [qw/ build singleton /];
+
+class Local::Normal
+{
+	build identifier returns (Int) { int rand 1_000_000_000 }
+}
+
+class Local::Single
+	extends Local::Normal
+	is singleton;
+
+ok(
+	Local::Single::->new->DOES('MooseX::Singleton::Role::Object')
+);
+
+ok not(
+	Local::Normal::->new->DOES('MooseX::Singleton::Role::Object')
+);
+
+is(
+	Local::Single::->new->identifier,
+	Local::Single::->new->identifier,
+);
+
+is(
+	Local::Single::->instance->identifier,
+	Local::Single::->instance->identifier,
+);
+
+use Test::More;
+eval "use Test::Pod 1.00";
+plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
+all_pod_files_ok();
+

File xt/02pod_coverage.t

+use Test::More skip_all => 'n/a';
+use Test::Pod::Coverage;
+
+my @modules = qw(MooseX::DeclareX::Plugin::singleton);
+pod_coverage_ok($_, "$_ is covered") for @modules;
+done_testing(scalar @modules);
+

File xt/03meta_uptodate.t

+use Test::More tests => 1;
+use Test::RDF::DOAP::Version;
+doap_version_ok('MooseX-DeclareX-Plugin-singleton', 'MooseX::DeclareX::Plugin::singleton');
+
+use Test::EOL;
+all_perl_files_ok();