Toby Inkster avatar Toby Inkster committed 8fde33e Draft

initial work

Comments (0)

Files changed (14)

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

lib/MooseX/RelatedClasses/Aliased.pm

+package MooseX::RelatedClasses::Aliased;
+
+use 5.010;
+use strict;
+use warnings;
+
+BEGIN {
+	$MooseX::RelatedClasses::Aliased::AUTHORITY = 'cpan:TOBYINK';
+	$MooseX::RelatedClasses::Aliased::VERSION   = '0.001';
+}
+
+use MooseX::RelatedClasses  0.001 qw( );
+
+use Carp                    0     qw( croak );
+use Devel::Caller           2.00  qw( caller_args );
+use Hook::AfterRuntime      0     qw( after_runtime );
+use List::MoreUtils         0     qw( uniq );
+use Moose::Util             2.00  qw( apply_all_roles );
+use Scalar::Util            0     qw( blessed );
+use Sub::Install            0     qw( install_sub );
+
+sub import
+{
+	my $caller = caller;
+	my ($class, $parameters) = @_;
+	
+	my @names = uniq(
+		grep defined,
+			@{ $parameters->{names} || [] },
+			$parameters->{name}
+	);
+	
+	foreach my $name (@names)
+	{
+		my $method = sprintf('%s_class', lc $name);
+		install_sub {
+			into => $caller,
+			as   => $name,
+			code => sub () {
+				1 if $];
+				my ($self) = caller_args(1);
+				blessed $self
+					or croak "'$name' cannot be called outside a method";
+				$self->$method;
+			},
+		}
+	}
+	
+	after_runtime {
+		apply_all_roles($caller, 'MooseX::RelatedClasses', $parameters);
+	};
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+MooseX::RelatedClasses::Aliased - sugar for MooseX::RelatedClasses
+
+=head1 SYNOPSIS
+
+Example from L<MooseX::RelatedClasses>...
+
+   package My::Framework;
+   use Moose;
+   use namespace::autoclean;
+   with 'MooseX::RelatedClasses' => {
+      name => 'Thinger',
+   };
+
+Later on you'd do this:
+
+   sub my_method {
+      my $self    = shift;
+      my $thinger = $self->thinger_class->new(...);
+      ...;
+   }
+
+Using this module...
+
+   package My::Framework;
+   use Moose;
+   use namespace::autoclean;
+   use MooseX::RelatedClasses::Aliased => {
+      name => 'Thinger',
+   };
+
+And:
+
+   sub my_method {
+      my $self    = shift;
+      my $thinger = Thinger->new(...);
+      ...;
+   }
+
+=head1 DESCRIPTION
+
+This is the spawn on L<MooseX::RelatedClasses> and L<aliased>.
+It's cute, but it relies on some pretty dodgy stuff under the hood.
+
+This idea doesn't work very well with inheritance right now.
+
+=head1 BUGS
+
+Please report any bugs to
+L<http://rt.cpan.org/Dist/Display.html?Queue=MooseX-RelatedClasses-Aliased>.
+
+=head1 SEE ALSO
+
+L<MooseX::RelatedClasses>,
+L<aliased>.
+
+=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.
+

meta/changes.pret

+# This file acts as the project's changelog.
+
+`MooseX-RelatedClasses-Aliased 0.001 cpan:TOBYINK`
+	issued  2012-10-29;
+	label   "Initial release".
+
+# This file contains general metadata about the project.
+
+@prefix : <http://usefulinc.com/ns/doap#>.
+
+`MooseX-RelatedClasses-Aliased`
+	:programming-language "Perl" ;
+	:shortdesc            "sugar for MooseX::RelatedClasses";
+	:homepage             <https://metacpan.org/release/MooseX-RelatedClasses-Aliased>;
+	:download-page        <https://metacpan.org/release/MooseX-RelatedClasses-Aliased>;
+	:bug-database         <http://rt.cpan.org/Dist/Display.html?Queue=MooseX-RelatedClasses-Aliased>;
+	:repository           [ a :HgRepository; :browse <https://bitbucket.org/tobyink/p5-moosex-relatedclasses-aliased> ];
+	:created              2012-10-29;
+	: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".
+

meta/makefile.pret

+# This file provides instructions for packaging.
+
+`MooseX-RelatedClasses-Aliased`
+	perl_version_from m`MooseX::RelatedClasses::Aliased`;
+	version_from      m`MooseX::RelatedClasses::Aliased`;
+	readme_from       m`MooseX::RelatedClasses::Aliased`;
+	test_requires     p`Test::More 0.61`;
+	requires          p`MooseX::RelatedClasses 0.001`;
+	requires          p`Carp 0`;
+	requires          p`Devel::Caller 2.00`;
+	requires          p`Hook::AfterRuntime 0`;
+	requires          p`List::MoreUtils 0`;
+	requires          p`Moose::Util 2.00`;
+	requires          p`Scalar::Util 0`;
+	requires          p`Sub::Install 0`;
+	.
+
+# This file contains data about the project developers.
+
+@prefix : <http://xmlns.com/foaf/0.1/>.
+
+cpan:TOBYINK
+	:name  "Toby Inkster";
+	:mbox  <mailto:tobyink@cpan.org>.
+
+use Test::More;
+
+BEGIN {
+	package Local::ABC;
+	use Moose;
+};
+
+BEGIN {
+	package My::Framework;
+	use Moose;
+	use MooseX::RelatedClasses::Aliased {
+		name => 'Thinger',
+	};
+	sub xyz {
+		Thinger->new;
+	}
+};
+
+my $obj = My::Framework->new( thinger_class => 'Local::ABC' );
+
+is($obj->thinger_class, 'Local::ABC');
+isa_ok($obj->xyz, 'Local::ABC');
+
+done_testing;
+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();
+

xt/02pod_coverage.t

+use XT::Util;
+use Test::More;
+use Test::Pod::Coverage;
+
+plan skip_all => __CONFIG__->{skip_all}
+	if __CONFIG__->{skip_all};
+
+if ( __CONFIG__->{modules} )
+{
+	my @modules = @{ __CONFIG__->{modules} };
+	pod_coverage_ok($_, "$_ is covered") for @modules;
+	done_testing(scalar @modules);
+}
+else
+{
+	all_pod_coverage_ok();
+}
+

xt/03meta_uptodate.config

+{"package":"MooseX-RelatedClasses-Aliased"}
+

xt/03meta_uptodate.t

+use XT::Util;
+use Test::More tests => 1;
+use Test::RDF::DOAP::Version;
+doap_version_ok(__CONFIG__->{package}, __CONFIG__->{version_from});
+
+use Test::EOL;
+all_perl_files_ok();
+use Test::Tabs;
+all_perl_files_ok();
+use XT::Util;
+use Test::More;
+use Test::HasVersion;
+
+plan skip_all => __CONFIG__->{skip_all}
+	if __CONFIG__->{skip_all};
+
+if ( __CONFIG__->{modules} )
+{
+	my @modules = @{ __CONFIG__->{modules} };
+	pm_version_ok($_, "$_ is covered") for @modules;
+	done_testing(scalar @modules);
+}
+else
+{
+	all_pm_version_ok();
+}
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.