Commits

Toby Inkster committed 5718e40 Draft

initial version

Comments (0)

Files changed (15)

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

lib/Module/Quote.pm

+package Module::Quote;
+
+use 5.008;
+use strict;
+use warnings;
+
+BEGIN {
+	$Module::Quote::AUTHORITY = 'cpan:TOBYINK';
+	$Module::Quote::VERSION   = '0.001';
+}
+
+sub import
+{
+	my $me = shift;
+	@_ = qw(qm) unless @_;
+	
+	require Module::Hash;
+	require PerlX::QuoteOperator;
+	
+	while (@_)
+	{
+		my $name = shift;
+		my %args = %{ ref $_[0] ? shift : {} };
+		
+		my $emulate = delete $args{emulate} || 'qq';
+		my $mh      = "Module::Hash"->new(%args);
+		
+		"PerlX::QuoteOperator"->new->import($name, {
+			-emulate => $emulate,
+			-parser  => 1,
+			-with    => sub ($) { $mh->use(@_) },
+		}, scalar caller);
+	}
+}
+
+1
+__END__
+
+=head1 NAME
+
+Module::Quote - a quote-like operator that requires modules for you
+
+=head1 SYNOPSIS
+
+	use Test::More tests => 1;
+	use Module::Quote;
+	
+	my $number = qm( Math::BigInt 1.00 )->new(42);
+	
+	isa_ok $number, "Math::BigInt";
+
+=head1 DESCRIPTION
+
+The C<< qm() >> quote-like operator will load a module and return its name.
+So the following should just work, even if you haven't C<< use >>d
+Math::BigInt in advance.
+
+	qm( Math::BigInt 1.00 )->new(42)
+
+The more usual invocation:
+
+	Math::BigInt->new(42)
+
+won't automatically load Math::BigInt, won't check a version number, and
+crucially is ambiguous! (See what happens when you define a sub called
+C<BigInt> in the C<Math> package.)
+
+The C<qm> operator interpolates variables, so this works too:
+
+	my $x = "BigInt 1.00";
+	qm( Math::$x )->new(42);
+
+You may export C<qm> with an alternative name:
+
+	use Module::Quote 'qmod';
+
+You may provide a hashref of options for the quote-like operator:
+
+	use Module::Quote qm => { emulate => 'q' };
+
+You can export the operator multiple times with different options:
+
+	use Module::Quote
+		qm  => { emulate => 'q' },
+		qqm => { emulate => 'qq' },
+	;
+
+The C<< optimistic >> and C<< prefix >> options from L<Module::Hash> are
+supported. As is C<< emulate >> which can be set to C<< "qq" >> (the default)
+or C<< "q" >> (to disable interpolation).
+
+=head1 BUGS
+
+Please report any bugs to
+L<http://rt.cpan.org/Dist/Display.html?Queue=Module-Quote>.
+
+=head1 SEE ALSO
+
+L<Module::Hash> - similar idea, but less magic.
+
+=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.
+
+`Module-Quote 0.001 cpan:TOBYINK`
+	issued  2012-11-23;
+	label   "Initial release".
+
+# This file contains general metadata about the project.
+
+@prefix : <http://usefulinc.com/ns/doap#>.
+
+`Module-Quote`
+	:programming-language "Perl" ;
+	:shortdesc            "a quote-like operator that requires modules for you";
+	:homepage             <https://metacpan.org/release/Module-Quote>;
+	:download-page        <https://metacpan.org/release/Module-Quote>;
+	:bug-database         <http://rt.cpan.org/Dist/Display.html?Queue=Module-Quote>;
+	:repository           [ a :HgRepository; :browse <https://bitbucket.org/tobyink/p5-module-quote> ];
+	:created              2012-11-16;
+	: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.
+
+`Module-Quote`
+	perl_version_from m`Module::Quote`;
+	version_from      m`Module::Quote`;
+	readme_from       m`Module::Quote`;
+	test_requires     p`Test::More 0.61`;
+	requires          p`Module::Hash 0.001`;
+	requires          p`PerlX::QuoteOperator 0.004`;
+.
+
+# 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 tests => 1;
+BEGIN { use_ok('Module::Quote') };
+
+use Test::More tests => 2;
+use Module::Quote qw( qm qp );
+
+my $number1 = qm( Math::BigInt )->new(42);
+my $number2 = qp( Math::BigInt 1.00 )->new(42);
+
+isa_ok $number1, "Math::BigInt";
+isa_ok $number2, "Math::BigInt";
+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":"Module-Quote"}
+

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.