Path-Dispatcher-1.05/000755 000765 000024 00000000000 12120355552 015047 5ustar00sartakstaff000000 000000 Path-Dispatcher-1.05/Changes000644 000765 000024 00000016224 12120355511 016342 0ustar00sartakstaff000000 000000 Revision history for Path-Dispatcher 1.05 Thu Mar 14 2013 eval q{$'} before regex match when needed to soothe bleadperl Thanks Dave Mitchell! http://www.nntp.perl.org/group/perl.perl5.porters/2013/03/msg200156.html 1.04 Thu Sep 1 2011 Explicitly depend on Test::Fatal (reported by Jérôme Quelin [rt.cpan.org #70666]) Convert all tests from Test::Exception to Test::Fatal 1.03 Tue Aug 30 2011 Provisional support for arbitrary payloads, not just code blocks, as results See https://github.com/sartak/path-dispatcher/blob/master/t/200-payload.t Eventually blocks will be deprecated, but not for a while. Internally blocks are rewritten as payloads so if you're doing deep magic with PD you may be exposed to that implementation detail. 1.02 Tue Nov 2 2010 Various improvements to the handling of $match->leftover with undef 1.01 Sun Oct 24 2010 Skip t/026-named-captures.t if you don't have 5.10.1 Give matches a ->parent for inspecting an Under prefix rule's captures etc 1.00 Sun Oct 17 2010 Bump to 1.0 to indicate back compat breakage Add match->named($key) for pulling out a named capture Use Try::Tiny to avoid swallowing exceptions (rafl) 0.16 Sun Oct 17 2010 ** BACKWARDS INCOMPATIBLE CHANGE: Pass the match object into rule ** blocks rather than assigning $1, $2, $3. Use ->pos(1), (2), (3), ** etc. instead. This cleans up the code a lot and makes ** Path-Dispatcher more flexible. Add support for named captures Make all attributes read-only. If you need something to be read-write, I am open to such a change. Just let me know! Make _dispatcher_rule private Remove trace/readable_attribute/name support. This wants to be implemented in a different, better, more comprehensive way. Add documentation for shell tab completion Plenty other updated documentation 0.15 Tue Mar 16 09:40:40 2010 ** Factored Path-Dispatcher-Declarative into its own distribution ** Be sure to update your dependency lists! Implement ->complete for Rule::Dispatch Add Path::Dispatcher::Rule::Alternation Implement case insensitivity for Rule::Eq Add Path::Dispatcher::Rule::Sequence - like Rule::Tokens but better! Add Path::Dispatcher::Rule::Enum Path autoboxing has been factored out into a private method for more overridability A few documentation improvements as usual :) 0.14 Thu Dec 31 13:18:19 2009 Add Path::Dispatcher->complete for tab-completion Handle delimiters better in Path::Dispatcher::Rule::Tokens Factor out a _prefix method for rules to simplify their logic 0.13 Sun Aug 9 13:38:19 2009 Add unshift_rule to classes that do Role::Rules Several distribution improvements 0.12 Fri Apr 17 03:21:05 2009 Fix a bug with undefined capture variables being converted to the empty string and throwing warnings (reported by obra) Give Path::Dispatcher::Rule::Dispatch a "rules" method 0.11 Wed Apr 15 02:47:50 2009 Fix some misnamed keys caused by de-AttributeHelper-ing Stop using some deprecated Moose features Doc fixes (Sartak and confound) 0.10 Fri Mar 6 23:40:42 2009 The way you specify token_delimiter and case_sensitive_tokens has changed! You now say: use Path::Dispatcher::Declarative -base, -defaults => { token_delimiter => '/', case_sensitive_tokens => 0, }; Added Path::Dispatcher::Cookbook (grink) Added Path::Dispatcher::Builder which now backs Path::Dispatcher::Declarative (grink) then {} rule which is an "always" with that uses next_rule (grink) chain {} rule which is like Catalyst's chain (grink) Remove the last vestiges of stages (Sartak) Many minor fixes (Sartak) 0.09 Mon Feb 9 21:12:18 2009 Avoid using method modifiers since it's potentially another dep. 0.08 Thu Feb 5 12:15:38 2009 Inline uses of MooseX::AttributeHelpers. Now use "Any::Moose" (basically Squirrel done right) 0.07 Wed Jan 28 01:39:37 2009 Paths are now boxed with the new Path::Dispatcher::Path. New rule type "Intersection" which matches only when each of its subrules match. New rule type "Metadata" which matches the optional metadata (a hash) of the path. The sugar for this is: on { foo => "bar" } New rule type "Eq" which just does basic string equality. Rules can now be named. In Path::Dispatcher::Declarative, each rule is named with its dispatcher's name and the file:line where the rule was defined. Dispatch tracing output, for debugging. Set environment variable PATH_DISPATCHER_TRACE to a number. The higher the number, the more output will be generated. The current maximum value of 10 will dump code references. 0.06 Sat Nov 15 21:02:29 2008 New rule type "Empty" which matches only the empty path. Declarative: on '' now matches only the empty path. 0.05 Sat Nov 15 16:36:41 2008 Improve test coverage New rule type "Always" which always matches. Match: ends_dispatch is now an attribute Rule::Tokens: Support for case insensitive matching Fix for tokens' type constraint Dispatcher: Allow rules to be specified in the constructor (a typo prevented it) Dispatch: first_match, has_match methods which do what you'd expect The run method will now collect return values and return them Declarative: redispatch_to sugar which adds a Dispatch rule "on '' => sub" as a special case will match all paths 0.04 Tue Oct 28 17:56:41 2008 Dist fixes 0.03 Tue Oct 28 17:42:47 2008 "rewrite" rules Super dispatchers are GONE! Yay. New Rule::Dispatch which just takes some other dispatcher. nothingmuch++ Rule::Tokens: Fix for always matching just a prefix whether you wanted to or not Make tokenization and untokenization into methods for overriding Declarative: -base is required, otherwise unrelated modules using your dispatcher would get their @ISA set! 0.02 Mon Oct 20 14:10:12 2008 Documentation! Prefix matches "under" rules Remove stages until they're actually needed Rule: The codeblock is no longer required Empty tokens are ignored The token attribute is now 'delimiter' instead of 'splitter' Allow regexes and alternations in the token rules Match: No longer Dispatch::Match Created by the Rule instead of the Dispatcher Declarative: You now must subclass Path::Dispatcher::Declarative Allow overriding the token delimiter 0.01 Wed Aug 27 11:04:18 2008 Initial release Path-Dispatcher-1.05/inc/000755 000765 000024 00000000000 12120355552 015620 5ustar00sartakstaff000000 000000 Path-Dispatcher-1.05/lib/000755 000765 000024 00000000000 12120355552 015615 5ustar00sartakstaff000000 000000 Path-Dispatcher-1.05/Makefile.PL000755 000765 000024 00000000607 12120355012 017016 0ustar00sartakstaff000000 000000 use inc::Module::Install; use Module::Install::GithubMeta; use Module::Install::ManifestSkip; use Module::Install::AutoManifest; name 'Path-Dispatcher'; all_from 'lib/Path/Dispatcher.pm'; githubmeta; requires 'Any::Moose' => '0.12'; requires 'Try::Tiny' => '0.02'; test_requires 'Test::More' => '0.88'; test_requires 'Test::Fatal'; manifest_skip; auto_manifest; WriteAll; Path-Dispatcher-1.05/MANIFEST000644 000765 000024 00000003244 12120355552 016203 0ustar00sartakstaff000000 000000 Changes inc/Module/Install.pm inc/Module/Install/AutoManifest.pm inc/Module/Install/Base.pm inc/Module/Install/Can.pm inc/Module/Install/Fetch.pm inc/Module/Install/GithubMeta.pm inc/Module/Install/Makefile.pm inc/Module/Install/ManifestSkip.pm inc/Module/Install/Metadata.pm inc/Module/Install/Win32.pm inc/Module/Install/WriteAll.pm lib/Path/Dispatcher.pm lib/Path/Dispatcher/Cookbook.pod lib/Path/Dispatcher/Dispatch.pm lib/Path/Dispatcher/Match.pm lib/Path/Dispatcher/Path.pm lib/Path/Dispatcher/Role/Rules.pm lib/Path/Dispatcher/Rule.pm lib/Path/Dispatcher/Rule/Alternation.pm lib/Path/Dispatcher/Rule/Always.pm lib/Path/Dispatcher/Rule/Chain.pm lib/Path/Dispatcher/Rule/CodeRef.pm lib/Path/Dispatcher/Rule/Dispatch.pm lib/Path/Dispatcher/Rule/Empty.pm lib/Path/Dispatcher/Rule/Enum.pm lib/Path/Dispatcher/Rule/Eq.pm lib/Path/Dispatcher/Rule/Intersection.pm lib/Path/Dispatcher/Rule/Metadata.pm lib/Path/Dispatcher/Rule/Regex.pm lib/Path/Dispatcher/Rule/Sequence.pm lib/Path/Dispatcher/Rule/Tokens.pm lib/Path/Dispatcher/Rule/Under.pm Makefile.PL MANIFEST This list of files META.yml t/000-compile.t t/001-api.t t/002-rule.t t/003-404.t t/004-run.t t/005-multi-rule.t t/006-abort.t t/007-coderef-matcher.t t/009-args.t t/010-return.t t/011-next-rule.t t/012-under.t t/013-tokens.t t/014-tokens-prefix.t t/015-regex-prefix.t t/017-intersection.t t/018-metadata.t t/019-intersection-metadata.t t/022-numbers-undef.t t/023-alternation.t t/024-sequence.t t/025-sequence-custom-rule.t t/026-named-captures.t t/027-custom-named-captures.t t/030-exceptions.t t/031-structured-match.t t/032-multiple-delimiter.t t/033-chain.t t/100-match-object.t t/200-payload.t t/901-return-values.t t/902-coderef.t Path-Dispatcher-1.05/META.yml000644 000765 000024 00000001346 12120355521 016320 0ustar00sartakstaff000000 000000 --- abstract: 'flexible and extensible dispatch' author: - 'Shawn M Moore, C<< >>' build_requires: ExtUtils::MakeMaker: 6.59 Test::Fatal: 0 Test::More: 0.88 configure_requires: ExtUtils::MakeMaker: 6.59 distribution_type: module dynamic_config: 1 generated_by: 'Module::Install version 1.06' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Path-Dispatcher no_index: directory: - inc - t requires: Any::Moose: 0.12 Try::Tiny: 0.02 perl: 5.8.1 resources: homepage: https://github.com/sartak/path-dispatcher/tree license: http://dev.perl.org/licenses/ repository: git://github.com/sartak/path-dispatcher.git version: 1.05 Path-Dispatcher-1.05/t/000755 000765 000024 00000000000 12120355552 015312 5ustar00sartakstaff000000 000000 Path-Dispatcher-1.05/t/000-compile.t000644 000765 000024 00000000125 12120355012 017411 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use_ok 'Path::Dispatcher'; done_testing; Path-Dispatcher-1.05/t/001-api.t000644 000765 000024 00000003037 12120355012 016540 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my @calls; my $dispatcher = Path::Dispatcher->new; $dispatcher->add_rule( Path::Dispatcher::Rule::Regex->new( regex => qr/foo/, block => sub { my $match = shift; push @calls, [@_]; }, ), ); is_deeply([splice @calls], [], "no calls to the rule block yet"); my $dispatch = $dispatcher->dispatch('foo'); is_deeply([splice @calls], [], "no calls to the rule block yet"); isa_ok($dispatch, 'Path::Dispatcher::Dispatch'); $dispatch->run; is_deeply([splice @calls], [ [] ], "finally invoked the rule block"); $dispatcher->run('foo'); is_deeply([splice @calls], [ [] ], "invoked the rule block on 'run'"); $dispatcher->add_rule( Path::Dispatcher::Rule::Regex->new( regex => qr/(bar)/, block => sub { my $match = shift; push @calls, $match->positional_captures; }, ), ); is_deeply([splice @calls], [], "no calls to the rule block yet"); $dispatch = $dispatcher->dispatch('bar'); is_deeply([splice @calls], [], "no calls to the rule block yet"); isa_ok($dispatch, 'Path::Dispatcher::Dispatch'); $dispatch->run; is_deeply([splice @calls], [ ['bar'] ], "finally invoked the rule block"); $dispatcher->run('bar'); is_deeply([splice @calls], [ ['bar'] ], "invoked the rule block on 'run'"); isa_ok($dispatch, 'Path::Dispatcher::Dispatch'); $dispatch->run; is_deeply([splice @calls], [ ['bar'] ], "invoked the rule block on 'run', makes sure ->pos etc are still correctly set"); done_testing; Path-Dispatcher-1.05/t/002-rule.t000644 000765 000024 00000001204 12120355012 016731 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher::Rule; my @calls; my $rule = Path::Dispatcher::Rule::Regex->new( regex => qr/^(..)(..)/, block => sub { push @calls, { vars => [$1, $2, $3], args => [@_], } }, ); my $match = $rule->match(Path::Dispatcher::Path->new('foobar')); isa_ok($match, 'Path::Dispatcher::Match'); is_deeply($match->positional_captures, ['fo', 'ob']); is_deeply([splice @calls], [], "block not called on match"); $rule->run; is_deeply([splice @calls], [{ vars => [undef, undef, undef], args => [], }], "block called on ->run"); done_testing; Path-Dispatcher-1.05/t/003-404.t000644 000765 000024 00000001056 12120355012 016277 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my @calls; my $dispatcher = Path::Dispatcher->new; $dispatcher->add_rule( Path::Dispatcher::Rule::Regex->new( regex => qr/foo/, block => sub { push @calls, [@_] }, ), ); my $dispatch = $dispatcher->dispatch('bar'); is_deeply([splice @calls], [], "no calls to the rule block yet"); isa_ok($dispatch, 'Path::Dispatcher::Dispatch'); is($dispatch->matches, 0, "no matches"); $dispatch->run; is_deeply([splice @calls], [], "no calls to the rule block"); done_testing; Path-Dispatcher-1.05/t/004-run.t000644 000765 000024 00000001375 12120355012 016601 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my $dispatcher = Path::Dispatcher->new( rules => [ Path::Dispatcher::Rule::Regex->new( regex => qr/^foobar/, block => sub { "foobar matched" }, ), ], ); my $result = $dispatcher->run("foobar"); is($result, "foobar matched"); $dispatcher->add_rule( Path::Dispatcher::Rule::Regex->new( regex => qr/^foo/, block => sub { "foo matched" }, ), ); $result = $dispatcher->run("foobar"); is($result, "foobar matched"); my $dispatch = $dispatcher->dispatch("foobar"); $result = $dispatch->run("foobar"); is($result, "foobar matched"); my @results = $dispatch->run("foobar"); is_deeply(\@results, ["foobar matched"]); done_testing; Path-Dispatcher-1.05/t/005-multi-rule.t000644 000765 000024 00000000616 12120355012 020072 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my @calls; my $dispatcher = Path::Dispatcher->new; for my $number (qw/first second/) { $dispatcher->add_rule( Path::Dispatcher::Rule::Regex->new( regex => qr/foo/, block => sub { push @calls, $number }, ), ); } $dispatcher->run('foo'); is_deeply(\@calls, ['first']); done_testing; Path-Dispatcher-1.05/t/006-abort.t000644 000765 000024 00000002143 12120355012 017100 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Test::Fatal; use Path::Dispatcher; my @calls; my $dispatcher = Path::Dispatcher->new; $dispatcher->add_rule( Path::Dispatcher::Rule::Regex->new( regex => qr/foo/, block => sub { push @calls, "on"; die "Path::Dispatcher abort\n"; }, ), ); $dispatcher->add_rule( Path::Dispatcher::Rule::Regex->new( regex => qr/foo/, block => sub { push @calls, "last"; }, ), ); my $dispatch = $dispatcher->dispatch('foo'); is_deeply([splice @calls], [], "no blocks called yet of course"); $dispatch->run; is_deeply([splice @calls], ['on'], "correctly aborted the entire dispatch"); $dispatcher->add_rule( Path::Dispatcher::Rule::Regex->new( regex => qr/bar/, block => sub { push @calls, "bar: before"; my $x = {}->(); push @calls, "bar: last"; }, ), ); like(exception { $dispatcher->run('bar'); }, qr/Not a CODE reference/); is_deeply([splice @calls], ['bar: before'], "regular dies pass through"); done_testing; Path-Dispatcher-1.05/t/007-coderef-matcher.t000644 000765 000024 00000001010 12120355012 021012 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my (@matches, @calls); my $dispatcher = Path::Dispatcher->new; $dispatcher->add_rule( Path::Dispatcher::Rule::CodeRef->new( matcher => sub { push @matches, $_; length > 5 ? {} : 0 }, block => sub { my $match = shift; push @calls, [@_] }, ), ); $dispatcher->run('foobar'); is_deeply([splice @matches], ['foobar']); is_deeply([splice @calls], [ [] ]); $dispatcher->run('other'); is($matches[0]->path, 'other'); done_testing; Path-Dispatcher-1.05/t/009-args.t000644 000765 000024 00000000737 12120355012 016737 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my @calls; my $dispatcher = Path::Dispatcher->new; $dispatcher->add_rule( Path::Dispatcher::Rule::Regex->new( regex => qr/foo/, block => sub { my $match = shift; push @calls, [@_] }, ), ); $dispatcher->run('foo', 42); is_deeply([splice @calls], [ [42], ]); my $dispatch = $dispatcher->dispatch('foo'); $dispatch->run(24); is_deeply([splice @calls], [ [24], ]); done_testing; Path-Dispatcher-1.05/t/010-return.t000644 000765 000024 00000001314 12120355012 017302 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; # we currently have no defined return strategy :/ my $dispatcher = Path::Dispatcher->new; $dispatcher->add_rule( Path::Dispatcher::Rule::Regex->new( regex => qr/foo/, block => sub { "foo" }, ), ); is_deeply([$dispatcher->run('foo', 42)], ["foo"]); my $dispatch = $dispatcher->dispatch('foo'); is_deeply([$dispatch->run(24)], ["foo"]); $dispatcher->add_rule( Path::Dispatcher::Rule::Regex->new( regex => qr/foo/, block => sub { "jinkies" }, ), ); is_deeply([$dispatcher->run('foo', 42)], ["foo"]); $dispatch = $dispatcher->dispatch('foo'); is_deeply([$dispatch->run(24)], ["foo"]); done_testing; Path-Dispatcher-1.05/t/011-next-rule.t000644 000765 000024 00000002230 12120355012 017705 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Test::Fatal; use Path::Dispatcher; my @calls; my $dispatcher = Path::Dispatcher->new; $dispatcher->add_rule( Path::Dispatcher::Rule::Regex->new( regex => qr/foo/, block => sub { push @calls, "on"; die "Path::Dispatcher next rule\n"; push @calls, "on post-die?!"; }, ), ); $dispatcher->add_rule( Path::Dispatcher::Rule::Regex->new( regex => qr/foo/, block => sub { push @calls, "last"; }, ), ); my $dispatch = $dispatcher->dispatch('foo'); is_deeply([splice @calls], [], "no blocks called yet of course"); $dispatch->run; is_deeply([splice @calls], ['on', 'last'], "correctly continued to the next rule"); $dispatcher->add_rule( Path::Dispatcher::Rule::Regex->new( regex => qr/bar/, block => sub { push @calls, "bar: before"; my $x = {}->(); push @calls, "bar: last"; }, ), ); like(exception { $dispatcher->run('bar'); }, qr/Not a CODE reference/); is_deeply([splice @calls], ['bar: before'], "regular dies pass through"); done_testing; Path-Dispatcher-1.05/t/012-under.t000644 000765 000024 00000004131 12120355012 017102 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my $predicate = Path::Dispatcher::Rule::Tokens->new( tokens => ['ticket'], prefix => 1, ); my $create = Path::Dispatcher::Rule::Tokens->new( tokens => ['create'], ); my $update = Path::Dispatcher::Rule::Tokens->new( tokens => ['update'], prefix => 1, ); my $under = Path::Dispatcher::Rule::Under->new( predicate => $predicate, rules => [$create, $update], ); my %tests = ( "ticket create" => {}, "ticket update" => {}, " ticket update " => { name => "whitespace doesn't matter for token-based rules", }, "ticket update foo" => { name => "'ticket update' rule is prefix", }, "ticket create foo" => { fail => 1, catchall => 1, name => "did not match 'ticket create foo' because it's not a suffix", }, "comment create" => { fail => 1, name => "did not match 'comment create' because the prefix is ticket", }, "ticket delete" => { fail => 1, catchall => 1, name => "did not match 'ticket delete' because delete is not a suffix", }, ); for my $path (keys %tests) { my $data = $tests{$path}; my $name = $data->{name} || $path; my $match = $under->match(Path::Dispatcher::Path->new($path)); $match = !$match if $data->{fail}; ok($match, $name); } my $catchall = Path::Dispatcher::Rule::Regex->new( regex => qr/()/, ); $under->add_rule($catchall); for my $path (keys %tests) { my $data = $tests{$path}; my $name = $data->{name} || $path; my $match = $under->match(Path::Dispatcher::Path->new($path)); $match = !$match if $data->{fail} && !$data->{catchall}; ok($match, $name); } # ensure that the predicate MUST be a prefix eval { local $SIG{__DIE__}; Path::Dispatcher::Rule::Under->new( predicate => Path::Dispatcher::Rule::Tokens->new( tokens => ['foo'], prefix => 0, ), ); }; like($@, qr/Attribute \(predicate\) does not pass the type constraint /, "predicate MUST match just a prefix"); done_testing; Path-Dispatcher-1.05/t/013-tokens.t000644 000765 000024 00000004137 12120355012 017277 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my @calls; my $dispatcher = Path::Dispatcher->new; $dispatcher->add_rule( Path::Dispatcher::Rule::Tokens->new( tokens => ['foo', 'bar'], block => sub { push @calls, shift->positional_captures }, ), ); $dispatcher->run('foo bar'); is_deeply([splice @calls], [ ['foo', 'bar'] ], "correctly populated number vars from [str, str] token rule"); $dispatcher->add_rule( Path::Dispatcher::Rule::Tokens->new( tokens => ['foo', qr/bar/], block => sub { push @calls, shift->positional_captures }, ), ); $dispatcher->run('foo bar'); is_deeply([splice @calls], [ ['foo', 'bar'] ], "ran the first [str, str] rule"); $dispatcher->run('foo barbaz'); is_deeply([splice @calls], [ ['foo', 'barbaz'] ], "ran the second [str, regex] rule"); $dispatcher->run('foo bar baz'); is_deeply([splice @calls], [], "no matches"); $dispatcher->add_rule( Path::Dispatcher::Rule::Tokens->new( tokens => [["Bat", "Super"], "Man"], block => sub { push @calls, shift->positional_captures }, ), ); $dispatcher->run('Super Man'); is_deeply([splice @calls], [ ['Super', 'Man'] ], "ran the [ [Str,Str], Str ] rule"); $dispatcher->run('Bat Man'); is_deeply([splice @calls], [ ['Bat', 'Man'] ], "ran the [ [Str,Str], Str ] rule"); $dispatcher->run('Aqua Man'); is_deeply([splice @calls], [ ], "no match"); $dispatcher->add_rule( Path::Dispatcher::Rule::Tokens->new( tokens => [[[[qr/Deep/]]], "Man"], block => sub { push @calls, shift->positional_captures }, ), ); $dispatcher->run('Deep Man'); is_deeply([splice @calls], [ ['Deep', 'Man'] ], "alternations can be arbitrarily deep"); $dispatcher->run('Not Appearing in this Dispatcher Man'); is_deeply([splice @calls], [ ], "no match"); my $rule = Path::Dispatcher::Rule::Tokens->new( tokens => ['path', 'dispatcher'], delimiter => '::', prefix => 1, case_sensitive => 0, ); my $match = $rule->match(Path::Dispatcher::Path->new('Path::Dispatcher::Rule::Tokens')); is($match->leftover, 'Rule::Tokens'); done_testing; Path-Dispatcher-1.05/t/014-tokens-prefix.t000644 000765 000024 00000001173 12120355012 020570 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my $rule = Path::Dispatcher::Rule::Tokens->new( tokens => ['foo', 'bar'], block => sub { }, prefix => 1, ); ok(!$rule->match(Path::Dispatcher::Path->new('foo')), "prefix means the rule matches a prefix of the path, not the other way around"); ok($rule->match(Path::Dispatcher::Path->new('foo bar')), "prefix matches the full path"); my $match = $rule->match(Path::Dispatcher::Path->new('foo bar baz')); ok($match, "prefix matches a prefix of the path"); is_deeply($match->positional_captures, ["foo", "bar"]); is($match->leftover, "baz"); done_testing; Path-Dispatcher-1.05/t/015-regex-prefix.t000644 000765 000024 00000001444 12120355012 020401 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my @calls; my $rule = Path::Dispatcher::Rule::Regex->new( regex => qr/^(foo)\s*(bar)/, block => sub { push @calls, [$1, $2] }, prefix => 1, ); ok(!$rule->match(Path::Dispatcher::Path->new('foo')), "prefix means the rule matches a prefix of the path, not the other way around"); ok($rule->match(Path::Dispatcher::Path->new('foo bar')), "prefix matches the full path"); ok($rule->match(Path::Dispatcher::Path->new('foo bar baz')), "prefix matches a prefix of the path"); my $match = $rule->match(Path::Dispatcher::Path->new('foobar:baz')); ok($match, "matched foobar:baz"); is_deeply($match->positional_captures, ["foo", "bar"], "match returns just the results"); is($match->leftover, ':baz', "leftovers"); done_testing; Path-Dispatcher-1.05/t/017-intersection.t000644 000765 000024 00000002465 12120355012 020510 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my @calls; my $dispatcher = Path::Dispatcher->new( rules => [ Path::Dispatcher::Rule::Intersection->new( rules => [ Path::Dispatcher::Rule::Tokens->new( tokens => ['foo'], block => sub { push @calls, 'tokens' }, ), Path::Dispatcher::Rule::Regex->new( regex => qr/^foo$/, block => sub { push @calls, 'regex' }, ), ], block => sub { push @calls, 'intersection' }, ), ], ); $dispatcher->run("foo"); is_deeply([splice @calls], ['intersection'], "the intersection matched; doesn't automatically run the subrules"); $dispatcher->run("food"); is_deeply([splice @calls], [], "each subrule of the intersection must match"); $dispatcher->run(" foo "); is_deeply([splice @calls], [], "each subrule of the intersection must match"); # test empty intersection $dispatcher = Path::Dispatcher->new( rules => [ Path::Dispatcher::Rule::Intersection->new( rules => [ ], block => sub { push @calls, 'intersection' }, ), ], ); $dispatcher->run("foo"); is_deeply([splice @calls], [], "no subrules means no match"); done_testing; Path-Dispatcher-1.05/t/018-metadata.t000644 000765 000024 00000001350 12120355012 017553 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my @calls; my $dispatcher = Path::Dispatcher->new( rules => [ Path::Dispatcher::Rule::Metadata->new( field => "http_method", matcher => Path::Dispatcher::Rule::Eq->new(string => "GET"), block => sub { push @calls, $_ }, ), ], ); $dispatcher->run(Path::Dispatcher::Path->new( path => "the path", metadata => { http_method => "GET", }, )); is_deeply([splice @calls], ["the path"]); $dispatcher->run(Path::Dispatcher::Path->new( path => "the path", metadata => { http_method => "POST", }, )); is_deeply([splice @calls], [], "metadata didn't match"); done_testing; Path-Dispatcher-1.05/t/019-intersection-metadata.t000644 000765 000024 00000002116 12120355012 022261 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my $dispatcher = Path::Dispatcher->new( rules => [ Path::Dispatcher::Rule::Intersection->new( block => sub { "creating a ticket" }, rules => [ Path::Dispatcher::Rule::Tokens->new( delimiter => '/', tokens => ['=', 'model', 'Ticket'], ), Path::Dispatcher::Rule::Metadata->new( field => 'http_method', matcher => Path::Dispatcher::Rule::Eq->new(string => 'POST'), ), ], ), ], ); my @results = $dispatcher->run(Path::Dispatcher::Path->new( path => "/=/model/Ticket", metadata => { http_method => "POST", }, )); is_deeply(\@results, ["creating a ticket"], "matched path and metadata"); @results = $dispatcher->run(Path::Dispatcher::Path->new( path => "/=/model/Ticket.yml", metadata => { http_method => "GET", }, )); is_deeply(\@results, [], "didn't match metadata"); done_testing; Path-Dispatcher-1.05/t/022-numbers-undef.t000644 000765 000024 00000000714 12120355012 020543 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my @recaptures; my $rule = Path::Dispatcher::Rule::Regex->new( regex => qr/^(foo)(bar)?(baz)$/, block => sub { push @recaptures, @{ shift->positional_captures }; }, ); my $match = $rule->match(Path::Dispatcher::Path->new("foobaz")); is_deeply($match->positional_captures, ['foo', undef, 'baz']); $match->run; is_deeply(\@recaptures, ['foo', undef, 'baz']); done_testing; Path-Dispatcher-1.05/t/023-alternation.t000644 000765 000024 00000003373 12120355012 020316 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my @calls; my $dispatcher = Path::Dispatcher->new( rules => [ Path::Dispatcher::Rule::Alternation->new( rules => [ Path::Dispatcher::Rule::Eq->new( string => 'foo', block => sub { push @calls, 'foo' }, ), Path::Dispatcher::Rule::Eq->new( string => 'bar', block => sub { push @calls, 'bar' }, ), ], block => sub { push @calls, 'alternation' }, ), ], ); $dispatcher->run("foo"); is_deeply([splice @calls], ['alternation'], "the alternation matched; doesn't automatically run the subrules"); $dispatcher->run("bar"); is_deeply([splice @calls], ['alternation'], "the alternation matched; doesn't automatically run the subrules"); $dispatcher->run("baz"); is_deeply([splice @calls], [], "each subrule of the intersection must match"); is_deeply([$dispatcher->complete("")], ["foo", "bar"]); is_deeply([$dispatcher->complete("f")], ["foo"]); is_deeply([$dispatcher->complete("b")], ["bar"]); is_deeply([$dispatcher->complete("fo")], ["foo"]); is_deeply([$dispatcher->complete("ba")], ["bar"]); is_deeply([$dispatcher->complete("foo")], []); is_deeply([$dispatcher->complete("bar")], []); is_deeply([$dispatcher->complete("fx")], []); is_deeply([$dispatcher->complete("baz")], []); # test empty alternation $dispatcher = Path::Dispatcher->new( rules => [ Path::Dispatcher::Rule::Alternation->new( rules => [ ], block => sub { push @calls, 'alternation' }, ), ], ); $dispatcher->run("foo"); is_deeply([splice @calls], [], "no subrules means no match"); done_testing; Path-Dispatcher-1.05/t/024-sequence.t000644 000765 000024 00000007367 12120355012 017616 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my @calls; my $dispatcher = Path::Dispatcher->new; $dispatcher->add_rule( Path::Dispatcher::Rule::Sequence->new( rules => [ Path::Dispatcher::Rule::Eq->new( string => 'foo', ), Path::Dispatcher::Rule::Eq->new( string => 'bar', ), ], block => sub { push @calls, shift->positional_captures }, ), ); $dispatcher->run('foo bar'); is_deeply([splice @calls], [ ['foo', 'bar'] ], "correctly populated number vars from [str, str] token rule"); $dispatcher->add_rule( Path::Dispatcher::Rule::Sequence->new( rules => [ Path::Dispatcher::Rule::Eq->new( string => 'foo', ), Path::Dispatcher::Rule::Regex->new( regex => qr/bar/, ), ], block => sub { push @calls, shift->positional_captures }, ), ); $dispatcher->run('foo bar'); is_deeply([splice @calls], [ ['foo', 'bar'] ], "ran the first [str, str] rule"); $dispatcher->run('foo barbaz'); is_deeply([splice @calls], [ ['foo', 'barbaz'] ], "ran the second [str, regex] rule"); $dispatcher->run('foo bar baz'); is_deeply([splice @calls], [ ], "no matches"); $dispatcher->add_rule( Path::Dispatcher::Rule::Sequence->new( rules => [ Path::Dispatcher::Rule::Alternation->new( rules => [ Path::Dispatcher::Rule::Eq->new( string => 'Bat', ), Path::Dispatcher::Rule::Eq->new( string => 'Super', ), ], ), Path::Dispatcher::Rule::Eq->new( string => 'Man', ), ], block => sub { push @calls, shift->positional_captures }, ), ); $dispatcher->run('Super Man'); is_deeply([splice @calls], [ ['Super', 'Man'] ], "ran the [ [Str,Str], Str ] rule"); $dispatcher->run('Bat Man'); is_deeply([splice @calls], [ ['Bat', 'Man'] ], "ran the [ [Str,Str], Str ] rule"); $dispatcher->run('Aqua Man'); is_deeply([splice @calls], [ ], "no match"); $dispatcher->add_rule( Path::Dispatcher::Rule::Sequence->new( rules => [ Path::Dispatcher::Rule::Alternation->new( rules => [ Path::Dispatcher::Rule::Alternation->new( rules => [ Path::Dispatcher::Rule::Alternation->new( rules => [ Path::Dispatcher::Rule::Regex->new( regex => qr/Deep/, ), ], ), ], ), ], ), Path::Dispatcher::Rule::Eq->new( string => "Man", ), ], block => sub { push @calls, shift->positional_captures }, ), ); $dispatcher->run('Deep Man'); is_deeply([splice @calls], [ ['Deep', 'Man'] ], "alternations can be arbitrarily deep"); $dispatcher->run('Not Appearing in this Dispatcher Man'); is_deeply([splice @calls], [ ], "no match"); my $rule = Path::Dispatcher::Rule::Sequence->new( rules => [ Path::Dispatcher::Rule::Eq->new( string => 'path', case_sensitive => 0, ), Path::Dispatcher::Rule::Eq->new( string => 'dispatcher', case_sensitive => 0, ), ], prefix => 1, delimiter => '::', ); my $match = $rule->match(Path::Dispatcher::Path->new('Path::Dispatcher::Rule::Tokens')); is($match->leftover, 'Rule::Tokens'); done_testing; Path-Dispatcher-1.05/t/025-sequence-custom-rule.t000644 000765 000024 00000010366 12120355012 022065 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my @calls; do { package MyApp::Dispatcher::Rule::Language; use Any::Moose; extends 'Path::Dispatcher::Rule::Enum'; has '+enum' => ( default => sub { [qw/ruby perl php python/] }, ); }; my $dispatcher = Path::Dispatcher->new( rules => [ Path::Dispatcher::Rule::Sequence->new( rules => [ Path::Dispatcher::Rule::Eq->new(string => 'use'), MyApp::Dispatcher::Rule::Language->new, ], block => sub { push @calls, shift->positional_captures }, ), ], ); $dispatcher->run("use perl"); is_deeply([splice @calls], [["use", "perl"]]); $dispatcher->run("use python"); is_deeply([splice @calls], [["use", "python"]]); $dispatcher->run("use php"); is_deeply([splice @calls], [["use", "php"]]); $dispatcher->run("use ruby"); is_deeply([splice @calls], [["use", "ruby"]]); $dispatcher->run("use c++"); is_deeply([splice @calls], []); is_deeply([$dispatcher->complete("u")], ["use"]); is_deeply([$dispatcher->complete("use")], ["use ruby", "use perl", "use php", "use python"]); is_deeply([$dispatcher->complete("use ")], ["use ruby", "use perl", "use php", "use python"]); is_deeply([$dispatcher->complete("use r")], ["use ruby"]); is_deeply([$dispatcher->complete("use p")], ["use perl", "use php", "use python"]); is_deeply([$dispatcher->complete("use pe")], ["use perl"]); is_deeply([$dispatcher->complete("use ph")], ["use php"]); is_deeply([$dispatcher->complete("use py")], ["use python"]); is_deeply([$dispatcher->complete("use px")], []); is_deeply([$dispatcher->complete("use x")], []); $dispatcher = Path::Dispatcher->new( rules => [ Path::Dispatcher::Rule::Sequence->new( rules => [ Path::Dispatcher::Rule::Eq->new(string => 'use'), MyApp::Dispatcher::Rule::Language->new, Path::Dispatcher::Rule::Eq->new(string => 'please'), ], block => sub { push @calls, shift->positional_captures }, ), ], ); $dispatcher->run("use perl"); is_deeply([splice @calls], []); $dispatcher->run("use perl please"); is_deeply([splice @calls], [["use", "perl", "please"]]); $dispatcher->run("use python"); is_deeply([splice @calls], []); $dispatcher->run("use python please"); is_deeply([splice @calls], [["use", "python", "please"]]); $dispatcher->run("use php"); is_deeply([splice @calls], []); $dispatcher->run("use php please"); is_deeply([splice @calls], [["use", "php", "please"]]); $dispatcher->run("use ruby"); is_deeply([splice @calls], []); $dispatcher->run("use ruby please"); is_deeply([splice @calls], [["use", "ruby", "please"]]); $dispatcher->run("use c++"); is_deeply([splice @calls], []); $dispatcher->run("use c++ please"); is_deeply([splice @calls], []); is_deeply([$dispatcher->complete("u")], ["use"]); is_deeply([$dispatcher->complete("use")], ["use ruby", "use perl", "use php", "use python"]); is_deeply([$dispatcher->complete("use ")], ["use ruby", "use perl", "use php", "use python"]); is_deeply([$dispatcher->complete("use r")], ["use ruby"]); is_deeply([$dispatcher->complete("use p")], ["use perl", "use php", "use python"]); is_deeply([$dispatcher->complete("use pe")], ["use perl"]); is_deeply([$dispatcher->complete("use ph")], ["use php"]); is_deeply([$dispatcher->complete("use py")], ["use python"]); is_deeply([$dispatcher->complete("use px")], []); is_deeply([$dispatcher->complete("use x")], []); is_deeply([$dispatcher->complete("use ruby")], ["use ruby please"]); is_deeply([$dispatcher->complete("use ruby ")], ["use ruby please"]); is_deeply([$dispatcher->complete("use ruby pl")], ["use ruby please"]); is_deeply([$dispatcher->complete("use ruby pleas")], ["use ruby please"]); is_deeply([$dispatcher->complete("use ruby please")], []); is_deeply([$dispatcher->complete("use ruby plx")], []); is_deeply([$dispatcher->complete("use perl")], ["use perl please"]); is_deeply([$dispatcher->complete("use perl ")], ["use perl please"]); is_deeply([$dispatcher->complete("use perl pl")], ["use perl please"]); is_deeply([$dispatcher->complete("use perl pleas")], ["use perl please"]); is_deeply([$dispatcher->complete("use perl please")], []); is_deeply([$dispatcher->complete("use perl plx")], []); done_testing; Path-Dispatcher-1.05/t/026-named-captures.t000644 000765 000024 00000001465 12120355012 020711 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; BEGIN { if ($] <= 5.010001) { plan skip_all => 'This test requires Perl 5.10.1'; } } use Path::Dispatcher; my $dispatcher = Path::Dispatcher->new( rules => [ Path::Dispatcher::Rule::Regex->new( regex => qr/^(\w+) (?\w+) (?\w+)?$/, block => sub { shift }, ), ], ); my $match = $dispatcher->run("positional named "); is_deeply($match->positional_captures, ["positional", "named", undef]); is_deeply($match->named_captures, { second => "named" }); $match = $dispatcher->run("positional firstnamed secondnamed"); is_deeply($match->positional_captures, ["positional", "firstnamed", "secondnamed"]); is_deeply($match->named_captures, { second => "firstnamed", third => "secondnamed" }); done_testing; Path-Dispatcher-1.05/t/027-custom-named-captures.t000644 000765 000024 00000001721 12120355012 022215 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; { package My::Rule::NamedEnum; use Any::Moose; extends 'Path::Dispatcher::Rule'; has name => ( is => 'ro', isa => 'Str', required => 1, ); has regex => ( is => 'ro', isa => 'RegexpRef', required => 1, ); sub _match { my $self = shift; my $path = shift; return unless $path =~ $self->regex; return { named_captures => { $self->name => $&, }, }; } } my $dispatcher = Path::Dispatcher->new( rules => [ My::Rule::NamedEnum->new( name => 'hoo-ah', regex => qr/^\w+::/, block => sub { shift }, ) ], ); my $match = $dispatcher->run("Foo::Bar"); is_deeply($match->positional_captures, []); is_deeply($match->named_captures, { "hoo-ah" => "Foo::" }); done_testing; Path-Dispatcher-1.05/t/030-exceptions.t000644 000765 000024 00000000534 12120355012 020151 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Test::Fatal; use Path::Dispatcher; my $dispatcher = Path::Dispatcher->new( rules => [ Path::Dispatcher::Rule::Always->new( block => sub { die "hi gang"; "foobar matched" }, ), ], ); like(exception { $dispatcher->run("foobar"); }, qr/hi gang/); done_testing; Path-Dispatcher-1.05/t/031-structured-match.t000644 000765 000024 00000002161 12120355012 021265 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my $outer = Path::Dispatcher::Rule::Regex->new( regex => qr/^(\w+) /, prefix => 1, ); my $inner = Path::Dispatcher::Rule::Regex->new( regex => qr/^(\w+)/, block => sub { return shift } ); my $dispatcher = Path::Dispatcher->new( rules => [ Path::Dispatcher::Rule::Under->new( predicate => $outer, rules => [ $inner ], ), ], ); my $match = $dispatcher->run("hello world"); my $parent = $match->parent; ok($parent, 'we have a parent too'); ok($match, 'matched'); is($parent->pos(1), 'hello', 'outer capture'); is($match->pos(1), 'world', 'inner capture'); is($parent->rule, $outer, 'outer rule'); is($match->rule, $inner, 'inner rule'); is_deeply($parent->positional_captures, ['hello'], 'all pos captures'); is_deeply($match->positional_captures, ['world'], 'all pos captures'); is($parent->path->path, 'hello world', 'outer path'); is($match->path->path, 'world', 'inner path'); is($parent->leftover, 'world', 'outer leftover'); is($match->leftover, undef, 'no inner leftover'); done_testing; Path-Dispatcher-1.05/t/032-multiple-delimiter.t000644 000765 000024 00000004046 12120355012 021603 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my @calls; my $dispatcher = Path::Dispatcher->new; $dispatcher->add_rule( Path::Dispatcher::Rule::Sequence->new( delimiter => ' ', rules => [ Path::Dispatcher::Rule::Eq->new( string => 'foo', ), Path::Dispatcher::Rule::Eq->new( string => 'bar', ), ], block => sub { push @calls, shift->positional_captures }, ), ); $dispatcher->run('foo bar'); is_deeply([splice @calls], [ ['foo', 'bar'] ], "correctly populated number vars from [str, str] token rule"); $dispatcher->run('foo bar'); is_deeply([splice @calls], [ ['foo', 'bar'] ], "correctly populated number vars from [str, str] token rule"); $dispatcher->run(' foo bar '); is_deeply([splice @calls], [ ['foo', 'bar'] ], "correctly populated number vars from [str, str] token rule"); $dispatcher = Path::Dispatcher->new; $dispatcher->add_rule( Path::Dispatcher::Rule::Sequence->new( delimiter => '/', rules => [ Path::Dispatcher::Rule::Eq->new( string => 'foo', ), Path::Dispatcher::Rule::Eq->new( string => 'bar', ), ], block => sub { push @calls, shift->positional_captures }, ), ); $dispatcher->run('/foo/bar'); is_deeply([splice @calls], [ ['foo', 'bar'] ], "correctly populated number vars from [str, str] token rule"); $dispatcher->run('/foo/bar/'); is_deeply([splice @calls], [ ['foo', 'bar'] ], "correctly populated number vars from [str, str] token rule"); $dispatcher->run('/foo//bar/'); is_deeply([splice @calls], [ ['foo', 'bar'] ], "correctly populated number vars from [str, str] token rule"); $dispatcher->run('foo/bar'); is_deeply([splice @calls], [ ['foo', 'bar'] ], "correctly populated number vars from [str, str] token rule"); $dispatcher->run('///foo///bar///'); is_deeply([splice @calls], [ ['foo', 'bar'] ], "correctly populated number vars from [str, str] token rule"); done_testing; Path-Dispatcher-1.05/t/033-chain.t000644 000765 000024 00000002445 12120355012 017060 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my @calls; my $dispatcher = Path::Dispatcher->new( rules => [ Path::Dispatcher::Rule::Under->new( predicate => Path::Dispatcher::Rule::Tokens->new( tokens => ['show'], prefix => 1, ), rules => [ Path::Dispatcher::Rule::Chain->new( block => sub { push @calls, 'chain' }, ), Path::Dispatcher::Rule::Tokens->new( tokens => ['inventory'], block => sub { push @calls, 'inventory' }, ), Path::Dispatcher::Rule::Tokens->new( tokens => ['score'], block => sub { push @calls, 'score' }, ), ], ), ], ); $dispatcher->run("show inventory"); is_deeply([splice @calls], [ 'chain', 'inventory' ]); $dispatcher->run("show score"); is_deeply([splice @calls], [ 'chain', 'score' ]); $dispatcher->run("show nothing"); is_deeply([splice @calls], [ ]); $dispatcher->run("do nothing"); is_deeply([splice @calls], [ ]); $dispatcher->run("do inventory"); is_deeply([splice @calls], [ ]); $dispatcher->run("do score"); is_deeply([splice @calls], [ ]); done_testing; Path-Dispatcher-1.05/t/100-match-object.t000644 000765 000024 00000001250 12120355012 020322 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Path::Dispatcher; my $match; my $dispatcher = Path::Dispatcher->new( rules => [ Path::Dispatcher::Rule::Regex->new( regex => qr/^(\w+) (Q)(Q) (\w+)$/, block => sub { $match = shift; }, ), ], ); $dispatcher->run("chewy QQ cute"); is_deeply($match->positional_captures, ["chewy", "Q", "Q", "cute"]); is_deeply($match->pos(1), "chewy"); is_deeply($match->pos(2), "Q"); is_deeply($match->pos(3), "Q"); is_deeply($match->pos(4), "cute"); is_deeply($match->pos(0), undef); is_deeply($match->pos(5), undef); is_deeply($match->pos(-1), "cute"); done_testing; Path-Dispatcher-1.05/t/200-payload.t000644 000765 000024 00000001270 12120355012 017416 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Test::Fatal; use Path::Dispatcher; my $dispatcher = Path::Dispatcher->new( rules => [ Path::Dispatcher::Rule::Regex->new( regex => qr/^(\w+)$/, payload => 'all the money', ), ], ); my $dispatch = $dispatcher->dispatch('hello'); ok($dispatch->has_matches); my $match = $dispatch->first_match; ok($match->rule->isa('Path::Dispatcher::Rule::Regex')); ok($match->rule->payload, 'all the money'); ok($match->payload, 'all the money'); like(exception { $dispatch->run }, qr/Payload is not a coderef/); like(exception { $dispatcher->run('bye') }, qr/Payload is not a coderef/); done_testing; Path-Dispatcher-1.05/t/901-return-values.t000644 000765 000024 00000000627 12120355012 020616 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Test::Fatal; use Path::Dispatcher; my $dispatcher = Path::Dispatcher->new( rules => [ Path::Dispatcher::Rule::CodeRef->new( matcher => sub { [{ cant_handle_complex_list_of_results => 1 }] }, ), ], ); like(exception { $dispatcher->dispatch('foo'); }, qr/Results returned from _match must be a hashref/); done_testing; Path-Dispatcher-1.05/t/902-coderef.t000644 000765 000024 00000000653 12120355012 017411 0ustar00sartakstaff000000 000000 use strict; use warnings; use Test::More; use Test::Fatal; use Path::Dispatcher::Rule::Tokens; my $rule = Path::Dispatcher::Rule::Tokens->new( tokens => ['bus', 'train'], ); like(exception { $rule->run; }, qr/^No codeblock to run/); my $match = $rule->match(Path::Dispatcher::Path->new('bus train')); ok($match, "matched the tokens"); like(exception { $match->run; }, qr/^No codeblock to run/); done_testing; Path-Dispatcher-1.05/lib/Path/000755 000765 000024 00000000000 12120355552 016511 5ustar00sartakstaff000000 000000 Path-Dispatcher-1.05/lib/Path/Dispatcher/000755 000765 000024 00000000000 12120355552 020577 5ustar00sartakstaff000000 000000 Path-Dispatcher-1.05/lib/Path/Dispatcher.pm000644 000765 000024 00000013266 12120355520 021140 0ustar00sartakstaff000000 000000 package Path::Dispatcher; use Any::Moose; use 5.008001; our $VERSION = '1.05'; use Path::Dispatcher::Rule; use Path::Dispatcher::Dispatch; use Path::Dispatcher::Path; use constant dispatch_class => 'Path::Dispatcher::Dispatch'; use constant path_class => 'Path::Dispatcher::Path'; with 'Path::Dispatcher::Role::Rules'; sub dispatch { my $self = shift; my $path = $self->_autobox_path(shift); my $dispatch = $self->dispatch_class->new; for my $rule ($self->rules) { $self->_dispatch_rule( rule => $rule, dispatch => $dispatch, path => $path, ); } return $dispatch; } sub _dispatch_rule { my $self = shift; my %args = @_; my @matches = $args{rule}->match($args{path}); $args{dispatch}->add_matches(@matches); return @matches; } sub run { my $self = shift; my $path = shift; my $dispatch = $self->dispatch($path); return $dispatch->run(@_); } sub complete { my $self = shift; my $path = $self->_autobox_path(shift); my %seen; return grep { !$seen{$_}++ } map { $_->complete($path) } $self->rules; } sub _autobox_path { my $self = shift; my $path = shift; unless (blessed($path) && $path->isa('Path::Dispatcher::Path')) { $path = $self->path_class->new( path => $path, ); } return $path; } __PACKAGE__->meta->make_immutable; no Any::Moose; 1; __END__ =head1 NAME Path::Dispatcher - flexible and extensible dispatch =head1 SYNOPSIS use Path::Dispatcher; my $dispatcher = Path::Dispatcher->new; $dispatcher->add_rule( Path::Dispatcher::Rule::Regex->new( regex => qr{^/(foo)/}, block => sub { warn shift->pos(1); }, ) ); $dispatcher->add_rule( Path::Dispatcher::Rule::Tokens->new( tokens => ['ticket', 'delete', qr/^\d+$/], delimiter => '/', block => sub { delete_ticket(shift->pos(3)) }, ) ); my $dispatch = $dispatcher->dispatch("/foo/bar"); die "404" unless $dispatch->has_matches; $dispatch->run; =head1 DESCRIPTION We really like L and wanted to use it for L's command line. The basic operation is that of dispatch. Dispatch takes a path and a list of rules, and it returns a list of matches. From there you can "run" the rules that matched. These phases are distinct so that, if you need to, you can inspect which rules were matched without ever running their codeblocks. Tab completion support is also available (see in particular L) for the dispatchers you write. Each rule may take a variety of different forms (which I think justifies the "flexible" adjective in the module's description). Some of the rule types are: =over 4 =item L Matches the path against a regular expression. =item L Match one of a set of strings. =item L Execute a coderef to determine whether the path matches the rule. So you can do anything you like. Though writing a domain-specific rule (see below) will enable better introspection and encoding intent. =item L Use another L to match the path. This facilitates both extending dispatchers (a bit like subclassing) and delegating to plugins. =back Since L is designed with good object-oriented programming practices, you can also write your own domain-specific rule classes (which earns it the "extensible" adjective). For example, in L, we have a custom rule for matching, and tab completing, record IDs. You may want to use L which gives you some sugar inspired by L. =head1 ATTRIBUTES =head2 rules A list of L objects. =head1 METHODS =head2 add_rule Adds a L to the end of this dispatcher's rule set. =head2 dispatch path -> dispatch Takes a string (the path) and returns a L object representing a list of matches (L objects). =head2 run path, args Dispatches on the path and then invokes the C method on the L object, for when you don't need to inspect the dispatch. The args are passed down directly into each rule codeblock. No other args are given to the codeblock. =head2 complete path -> strings Given a path, consult each rule for possible completions for the path. This is intended for tab completion. You can use it with L like so: $term->Attribs->{completion_function} = sub { my ($last_word, $line, $start) = @_; my @matches = map { s/^.* //; $_ } $dispatcher->complete($line); return @matches; }; This API is experimental and subject to change. In particular I think I want to return an object that resembles L. =head1 AUTHOR Shawn M Moore, C<< >> =head1 SEE ALSO =over 4 =item L =item L =item L =item L =item L =item L =item L =item L =item L - Not quite ready for release =back =head1 COPYRIGHT & LICENSE Copyright 2008-2011 Best Practical Solutions. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Path-Dispatcher-1.05/lib/Path/Dispatcher/Cookbook.pod000644 000765 000024 00000004356 12120355012 023050 0ustar00sartakstaff000000 000000 =pod =head1 NAME Path::Dispatcher::Cookbook - A cookbook for Path::Dispatcher =head1 RECIPES =head2 How can I change the path delimiter from a space ' ' to a slash '/'? When importing the L sugar, specify the C option for the C group. package My::Dispatcher; use Path::Dispatcher::Declarative -base, -default => { token_delimiter => '/', }; Or define a subclass of L with a C method: package Web::Dispatcher::Maker; use base 'Path::Dispatcher::Declarative'; use constant token_delimiter => '/'; package My::Dispatcher; use Web::Dispatcher::Maker -base; =head2 How can I do rule chaining (like in Catalyst)? You can use a C rule approximate chaining behavior: package MyDispatcher; use Path::Dispatcher::Declarative -base; under show => sub { chain { print "Displaying "; }; on inventory => sub { print "inventory:\n"; ... }; on score => sub { print "score:\n"; ... }; }; package main; MyDispatcher->run("show inventory"); # "Displaying inventory:\n ..." MyDispatcher->run("show score"); # "Displaying score:\n ..." =head2 How can I configure tab completion for shells? First add a dispatcher rule for generating completions based on the path. Here we name it _gencomp, so that if the user types "app _gencomp hel" it will print out the various completions of "hel". on qr/^_gencomp\s*(.*)/ => sub { my $prefix = shift->pos(1); $prefix = "" if !defined($prefix); print "$_\n" for dispatcher->complete($prefix); }; Then tell your shell about how to use _gencomp. For zsh it might look like this (replace "APP" with your binary name): /usr/share/zsh/site-functions/_APP: #compdef APP typeset -a APP_completions APP_completions=($($words[1] _gencomp $words[2,-1])) compadd $APP_completions For bash it might look like this: /etc/bash_completion.d/APP.bash: function _APP_() { COMPREPLY=($($1 _gencomp ${COMP_WORDS[COMP_CWORD]})) } complete -F _APP_ APP =cut Path-Dispatcher-1.05/lib/Path/Dispatcher/Dispatch.pm000644 000765 000024 00000004752 12120355012 022673 0ustar00sartakstaff000000 000000 package Path::Dispatcher::Dispatch; use Any::Moose; use Try::Tiny; use Path::Dispatcher::Match; has _matches => ( is => 'ro', isa => 'ArrayRef', default => sub { [] }, ); sub add_match { my $self = shift; $_->isa('Path::Dispatcher::Match') or confess "$_ is not a Path::Dispatcher::Match" for @_; push @{ $self->{_matches} }, @_; } sub matches { @{ shift->{_matches} } } sub has_match { scalar @{ shift->{_matches} } } sub first_match { shift->{_matches}[0] } # aliases __PACKAGE__->meta->add_method(add_matches => __PACKAGE__->can('add_match')); __PACKAGE__->meta->add_method(has_matches => __PACKAGE__->can('has_match')); sub run { my $self = shift; my @args = @_; my @matches = $self->matches; my @results; while (my $match = shift @matches) { my $exception; try { local $SIG{__DIE__} = 'DEFAULT'; push @results, $match->run(@args); # we always stop after the first match UNLESS they explicitly # ask to continue on to the next rule die "Path::Dispatcher abort\n"; } catch { $exception = $_; }; last if $exception =~ /^Path::Dispatcher abort\n/; next if $exception =~ /^Path::Dispatcher next rule\n/; die $exception; } return @results if wantarray; return $results[0]; } __PACKAGE__->meta->make_immutable; no Any::Moose; 1; __END__ =head1 NAME Path::Dispatcher::Dispatch - a list of matches =head1 SYNOPSIS my $dispatcher = Path::Dispatcher->new( rules => [ Path::Dispatcher::Rule::Tokens->new( tokens => [ 'attack', qr/^\w+$/ ], block => sub { attack(shift->pos(2)) }, ), ], ); my $dispatch = $dispatcher->dispatch("attack goblin"); $dispatch->matches; # list of matches (in this case, one) $dispatch->has_matches; # whether there were any matches $dispatch->run; # attacks the goblin =head1 DESCRIPTION Dispatching creates a C which is little more than a (possibly empty!) list of matches. =head1 ATTRIBUTES =head2 matches The list of L that correspond to the rules that were matched. =head1 METHODS =head2 run Executes the first match. Each match's L method is evaluated in scalar context. The return value of this method is a list of these scalars (or the first if called in scalar context). =cut Path-Dispatcher-1.05/lib/Path/Dispatcher/Match.pm000644 000765 000024 00000005605 12120355012 022166 0ustar00sartakstaff000000 000000 package Path::Dispatcher::Match; use Any::Moose; use Path::Dispatcher::Path; use Path::Dispatcher::Rule; has path => ( is => 'ro', isa => 'Path::Dispatcher::Path', required => 1, ); has leftover => ( is => 'ro', isa => 'Str', ); has rule => ( is => 'ro', isa => 'Path::Dispatcher::Rule', required => 1, handles => ['payload'], ); has positional_captures => ( is => 'ro', isa => 'ArrayRef[Str|Undef]', default => sub { [] }, ); has named_captures => ( is => 'ro', isa => 'HashRef[Str|Undef]', default => sub { {} }, ); has parent => ( is => 'ro', isa => 'Path::Dispatcher::Match', predicate => 'has_parent', ); sub run { my $self = shift; local $_ = $self->path; return scalar $self->rule->run($self, @_); } sub pos { my $self = shift; my $index = shift; return undef if $index == 0; $index-- if $index > 0; return $self->positional_captures->[$index]; } sub named { my $self = shift; my $key = shift; return $self->named_captures->{$key}; } __PACKAGE__->meta->make_immutable; no Any::Moose; 1; __END__ =head1 NAME Path::Dispatcher::Match - the result of a successful rule match =head1 SYNOPSIS my $rule = Path::Dispatcher::Rule::Tokens->new( tokens => [ 'attack', qr/^\w+$/ ], block => sub { my $match = shift; attack($match->pos(2)) }, ); my $match = $rule->match("attack dragon"); # introspection $match->path # "attack dragon" $match->leftover # empty string (populated with prefix rules) $match->rule # $rule $match->positional_captures # ["attack", "dragon"] (decided by the rule) $match->pos(1) # "attack" $match->pos(2) # "dragon" $match->run # attack("dragon") =head1 DESCRIPTION If a L successfully matches a path, it creates one or more C objects. =head1 ATTRIBUTES =head2 rule The L that created this match. =head2 path The path that the rule matched. =head2 leftover The rest of the path. This is populated when the rule matches a prefix of the path. =head2 positional_captures Any positional captures generated by the rule. For example, L populates this with the capture variables. =head2 named_captures Any named captures generated by the rule. For example, L populates this with named captures. =head2 parent The parent match object, if applicable (which may be set if this match is the child of, for exampl, a L prefix) =head1 METHODS =head2 run Executes the rule's codeblock with the same arguments. =head2 pos($i) Returns the C<$i>th positional capture, 1-indexed. =cut Path-Dispatcher-1.05/lib/Path/Dispatcher/Path.pm000644 000765 000024 00000002610 12120355012 022017 0ustar00sartakstaff000000 000000 package Path::Dispatcher::Path; use Any::Moose; use overload q{""} => sub { shift->path }; has path => ( is => 'ro', isa => 'Str', predicate => 'has_path', ); has metadata => ( is => 'ro', isa => 'HashRef', predicate => 'has_metadata', ); # allow Path::Dispatcher::Path->new($path) sub BUILDARGS { my $self = shift; if (@_ == 1 && !ref($_[0])) { unshift @_, 'path'; } $self->SUPER::BUILDARGS(@_); }; sub clone_path { my $self = shift; my $path = shift; return $self->meta->clone_object($self, path => $path, @_); } sub get_metadata { my $self = shift; my $name = shift; return $self->metadata->{$name}; } __PACKAGE__->meta->make_immutable; no Any::Moose; 1; __END__ =head1 NAME Path::Dispatcher::Path - path and some optional metadata =head1 SYNOPSIS my $path = Path::Dispatcher::Path->new( path => "/REST/Ticket/1", metadata => { http_method => "DELETE", }, ); $path->path; # /REST/Ticket/1 $path->get_metadata("http_method"); # DELETE =head1 ATTRIBUTES =head2 path A string representing the path. C is basically a boxed string. :) =head2 metadata A hash representing arbitrary metadata. The L rule is designed to match against members of this hash. =cut Path-Dispatcher-1.05/lib/Path/Dispatcher/Role/000755 000765 000024 00000000000 12120355552 021500 5ustar00sartakstaff000000 000000 Path-Dispatcher-1.05/lib/Path/Dispatcher/Rule/000755 000765 000024 00000000000 12120355552 021506 5ustar00sartakstaff000000 000000 Path-Dispatcher-1.05/lib/Path/Dispatcher/Rule.pm000644 000765 000024 00000007315 12120355012 022041 0ustar00sartakstaff000000 000000 package Path::Dispatcher::Rule; use Any::Moose; use Path::Dispatcher::Match; use constant match_class => "Path::Dispatcher::Match"; has payload => ( is => 'ro', predicate => 'has_payload', ); has prefix => ( is => 'ro', isa => 'Bool', default => 0, ); # support for deprecated "block" attribute sub block { shift->payload(@_) } sub has_block { shift->has_payload(@_) } override BUILDARGS => sub { my $self = shift; my $args = super; $args->{payload} ||= delete $args->{block}; return $args; }; sub match { my $self = shift; my $path = shift; my %args = @_; my $result; if ($self->prefix) { $result = $self->_prefix_match($path); } else { $result = $self->_match($path); } return if !$result; if (ref($result) ne 'HASH') { die "Results returned from _match must be a hashref"; } my $match = $self->match_class->new( path => $path, rule => $self, %{ $args{extra_constructor_args} || {} }, %$result, ); return $match; } sub complete { return (); # no completions } sub _prefix_match { my $self = shift; return $self->_match(@_); } sub run { my $self = shift; my $payload = $self->payload; die "No codeblock to run" if !$payload; die "Payload is not a coderef" if ref($payload) ne 'CODE'; $self->payload->(@_); } __PACKAGE__->meta->make_immutable; no Any::Moose; # don't require others to load our subclasses explicitly require Path::Dispatcher::Rule::Alternation; require Path::Dispatcher::Rule::Always; require Path::Dispatcher::Rule::Chain; require Path::Dispatcher::Rule::CodeRef; require Path::Dispatcher::Rule::Dispatch; require Path::Dispatcher::Rule::Empty; require Path::Dispatcher::Rule::Enum; require Path::Dispatcher::Rule::Eq; require Path::Dispatcher::Rule::Intersection; require Path::Dispatcher::Rule::Metadata; require Path::Dispatcher::Rule::Regex; require Path::Dispatcher::Rule::Sequence; require Path::Dispatcher::Rule::Tokens; require Path::Dispatcher::Rule::Under; 1; __END__ =head1 NAME Path::Dispatcher::Rule - predicate and codeblock =head1 SYNOPSIS my $rule = Path::Dispatcher::Rule::Regex->new( regex => qr/^quit/, block => sub { die "Program terminated by user.\n" }, ); $rule->match("die"); # undef, because "die" !~ /^quit/ my $match = $rule->match("quit"); # creates a Path::Dispatcher::Match $match->run; # exits the program =head1 DESCRIPTION A rule has a predicate and an optional codeblock. Rules can be matched (which checks the predicate against the path) and they can be ran (which invokes the codeblock). This class is not meant to be instantiated directly, because there is no predicate matching function. Instead use one of the subclasses such as L. =head1 ATTRIBUTES =head2 block An optional block of code to be run. Please use the C method instead of invoking this attribute directly. =head2 prefix A boolean indicating whether this rule can match a prefix of a path. If false, then the predicate must match the entire path. One use-case is that you may want a catch-all rule that matches anything beginning with the token C. The unmatched, latter part of the path will be available in the match object. =head1 METHODS =head2 match path -> match Takes a path and returns a L object if it matched the predicate, otherwise C. The match object contains information about the match, such as the results (e.g. for regex, a list of the captured variables), the C path if C matching was used, etc. =head2 run Runs the rule's codeblock. If none is present, it throws an exception. =cut Path-Dispatcher-1.05/lib/Path/Dispatcher/Rule/Alternation.pm000644 000765 000024 00000001206 12120355012 024312 0ustar00sartakstaff000000 000000 package Path::Dispatcher::Rule::Alternation; use Any::Moose; extends 'Path::Dispatcher::Rule'; with 'Path::Dispatcher::Role::Rules'; sub _match { my $self = shift; my $path = shift; my @rules = $self->rules; return if @rules == 0; for my $rule (@rules) { return {} if $rule->match($path); } return; } sub complete { my $self = shift; return map { $_->complete(@_) } $self->rules; } __PACKAGE__->meta->make_immutable; no Any::Moose; 1; __END__ =head1 NAME Path::Dispatcher::Rule::Alternation - any rule must match =head1 SYNOPSIS =head1 DESCRIPTION =head1 ATTRIBUTES =head2 rules =cut Path-Dispatcher-1.05/lib/Path/Dispatcher/Rule/Always.pm000644 000765 000024 00000000717 12120355012 023300 0ustar00sartakstaff000000 000000 package Path::Dispatcher::Rule::Always; use Any::Moose; extends 'Path::Dispatcher::Rule'; sub _match { my $self = shift; my $path = shift; return { leftover => $path->path, }; } __PACKAGE__->meta->make_immutable; no Any::Moose; 1; __END__ =head1 NAME Path::Dispatcher::Rule::Always - always matches =head1 DESCRIPTION Rules of this class always match. If a prefix match is requested, the full path is returned as leftover. =cut Path-Dispatcher-1.05/lib/Path/Dispatcher/Rule/Chain.pm000644 000765 000024 00000000727 12120355012 023063 0ustar00sartakstaff000000 000000 package Path::Dispatcher::Rule::Chain; use Any::Moose; extends 'Path::Dispatcher::Rule::Always'; override payload => sub { my $self = shift; my $payload = super; if (!@_) { return sub { $payload->(@_); die "Path::Dispatcher next rule\n"; # FIXME From Path::Dispatcher::Declarative... maybe this should go in a common place? }; } return $payload; }; __PACKAGE__->meta->make_immutable; no Any::Moose; 1; Path-Dispatcher-1.05/lib/Path/Dispatcher/Rule/CodeRef.pm000644 000765 000024 00000002422 12120355012 023342 0ustar00sartakstaff000000 000000 package Path::Dispatcher::Rule::CodeRef; use Any::Moose; extends 'Path::Dispatcher::Rule'; has matcher => ( is => 'ro', isa => 'CodeRef', required => 1, ); sub _match { my $self = shift; my $path = shift; local $_ = $path; return $self->matcher->($path); } __PACKAGE__->meta->make_immutable; no Any::Moose; 1; __END__ =head1 NAME Path::Dispatcher::Rule::CodeRef - predicate is any subroutine =head1 SYNOPSIS my $rule = Path::Dispatcher::Rule::CodeRef->new( matcher => sub { time % 2 }, block => sub { warn "Odd time!" }, ); my $undef = $rule->match("foo"); # even time; no match :) my $match = $rule->match("foo"); # odd time; creates a Path::Dispatcher::Match $rule->run; # warns "Odd time!" =head1 DESCRIPTION Rules of this class can match arbitrarily complex values. This should be used only when there is no other recourse, because there's no way we can inspect how things match. You're much better off creating a custom subclass of L if at all possible. =head1 ATTRIBUTES =head2 matcher A coderef that returns C if there's no match, otherwise a list of strings (the results). The coderef receives the path object as its argument, and the path string as C<$_>. =cut Path-Dispatcher-1.05/lib/Path/Dispatcher/Rule/Dispatch.pm000644 000765 000024 00000002307 12120355012 023574 0ustar00sartakstaff000000 000000 package Path::Dispatcher::Rule::Dispatch; use Any::Moose; extends 'Path::Dispatcher::Rule'; has dispatcher => ( is => 'ro', isa => 'Path::Dispatcher', required => 1, handles => ['rules', 'complete'], ); sub match { my $self = shift; my $path = shift; my $dispatch = $self->dispatcher->dispatch($path); return $dispatch->matches; } __PACKAGE__->meta->make_immutable; no Any::Moose; 1; __END__ =head1 NAME Path::Dispatcher::Rule::Dispatch - redispatch =head1 SYNOPSIS my $dispatcher = Path::Dispatcher->new( rules => [ Path::Dispatcher::Rule::Tokens->new( tokens => [ 'help' ], block => sub { show_help }, ), Path::Dispatcher::Rule::Tokens->new( tokens => [ 'quit' ], block => sub { exit }, ), ], ); my $rule = Path::Dispatcher::Rule::Dispatch->new( dispatcher => $dispatcher, ); $rule->run("help"); =head1 DESCRIPTION Rules of this class use another dispatcher to match the path. =head1 ATTRIBUTES =head2 dispatcher A L object. Its matches will be returned by matching this rule. =cut Path-Dispatcher-1.05/lib/Path/Dispatcher/Rule/Empty.pm000644 000765 000024 00000000664 12120355012 023137 0ustar00sartakstaff000000 000000 package Path::Dispatcher::Rule::Empty; use Any::Moose; extends 'Path::Dispatcher::Rule'; sub _match { my $self = shift; my $path = shift; return if length $path->path; return { leftover => $path->path }; } __PACKAGE__->meta->make_immutable; no Any::Moose; 1; __END__ =head1 NAME Path::Dispatcher::Rule::Empty - matches only the empty path =head1 DESCRIPTION Rules of this class match only the empty path. =cut Path-Dispatcher-1.05/lib/Path/Dispatcher/Rule/Enum.pm000644 000765 000024 00000004526 12120355012 022746 0ustar00sartakstaff000000 000000 package Path::Dispatcher::Rule::Enum; use Any::Moose; extends 'Path::Dispatcher::Rule'; has enum => ( is => 'ro', isa => 'ArrayRef[Str]', required => 1, ); has case_sensitive => ( is => 'ro', isa => 'Bool', default => 1, ); sub _match { my $self = shift; my $path = shift; if ($self->case_sensitive) { for my $value (@{ $self->enum }) { return {} if $path->path eq $value; } } else { for my $value (@{ $self->enum }) { return {} if lc($path->path) eq lc($value); } } return; } sub _prefix_match { my $self = shift; my $path = shift; my $truncated = substr($path->path, 0, length($self->string)); if ($self->case_sensitive) { for my $value (@{ $self->enum }) { next unless $truncated eq $value; return { leftover => substr($path->path, length($self->string)), }; } } else { for my $value (@{ $self->enum }) { next unless lc($truncated) eq lc($value); return { leftover => substr($path->path, length($self->string)), }; } } return; } sub complete { my $self = shift; my $path = shift->path; my @completions; # by convention, complete does include the path itself if it # is a complete match my @enum = grep { length($path) < length($_) } @{ $self->enum }; if ($self->case_sensitive) { for my $value (@enum) { my $partial = substr($value, 0, length($path)); push @completions, $value if $partial eq $path; } } else { for my $value (@enum) { my $partial = substr($value, 0, length($path)); push @completions, $value if lc($partial) eq lc($path); } } return @completions; } __PACKAGE__->meta->make_immutable; no Any::Moose; 1; __END__ =head1 NAME Path::Dispatcher::Rule::Enum - one of a list of strings must match =head1 SYNOPSIS my $rule = Path::Dispatcher::Rule::Enum->new( enum => [qw(perl ruby python php)], block => sub { warn "I love " . shift->pos(1) }, ); =head1 DESCRIPTION Rules of this class check whether the path matches any of its L strings. =head1 ATTRIBUTES =head2 enum =head2 case_sensitive =cut Path-Dispatcher-1.05/lib/Path/Dispatcher/Rule/Eq.pm000644 000765 000024 00000003407 12120355012 022404 0ustar00sartakstaff000000 000000 package Path::Dispatcher::Rule::Eq; use Any::Moose; extends 'Path::Dispatcher::Rule'; has string => ( is => 'ro', isa => 'Str', required => 1, ); has case_sensitive => ( is => 'ro', isa => 'Bool', default => 1, ); sub _match { my $self = shift; my $path = shift; if ($self->case_sensitive) { return unless $path->path eq $self->string; } else { return unless lc($path->path) eq lc($self->string); } return {}; } sub _prefix_match { my $self = shift; my $path = shift; my $truncated = substr($path->path, 0, length($self->string)); if ($self->case_sensitive) { return unless $truncated eq $self->string; } else { return unless lc($truncated) eq lc($self->string); } return { leftover => substr($path->path, length($self->string)), }; } sub complete { my $self = shift; my $path = shift->path; my $completed = $self->string; # by convention, complete does include the path itself if it # is a complete match return if length($path) >= length($completed); my $partial = substr($completed, 0, length($path)); if ($self->case_sensitive) { return unless $partial eq $path; } else { return unless lc($partial) eq lc($path); } return $completed; } __PACKAGE__->meta->make_immutable; no Any::Moose; 1; __END__ =head1 NAME Path::Dispatcher::Rule::Eq - predicate is a string equality =head1 SYNOPSIS my $rule = Path::Dispatcher::Rule::Eq->new( string => 'comment', block => sub { display_comment(shift->pos(1)) }, ); =head1 DESCRIPTION Rules of this class simply check whether the string is equal to the path. =head1 ATTRIBUTES =head2 string =cut Path-Dispatcher-1.05/lib/Path/Dispatcher/Rule/Intersection.pm000644 000765 000024 00000001062 12120355012 024500 0ustar00sartakstaff000000 000000 package Path::Dispatcher::Rule::Intersection; use Any::Moose; extends 'Path::Dispatcher::Rule'; with 'Path::Dispatcher::Role::Rules'; sub _match { my $self = shift; my $path = shift; my @rules = $self->rules; return if @rules == 0; for my $rule (@rules) { return unless $rule->match($path); } return {}; } __PACKAGE__->meta->make_immutable; no Any::Moose; 1; __END__ =head1 NAME Path::Dispatcher::Rule::Intersection - all rules must match =head1 SYNOPSIS =head1 DESCRIPTION =head1 ATTRIBUTES =head2 rules =cut Path-Dispatcher-1.05/lib/Path/Dispatcher/Rule/Metadata.pm000644 000765 000024 00000002454 12120355012 023560 0ustar00sartakstaff000000 000000 package Path::Dispatcher::Rule::Metadata; use Any::Moose; extends 'Path::Dispatcher::Rule'; has field => ( is => 'ro', isa => 'Str', required => 1, ); has matcher => ( is => 'ro', isa => 'Path::Dispatcher::Rule', required => 1, ); sub _match { my $self = shift; my $path = shift; my $got = $path->get_metadata($self->field); # wow, offensive.. but powerful my $metadata_path = $path->clone_path($got); return unless $self->matcher->match($metadata_path); return { leftover => $path->path, }; } __PACKAGE__->meta->make_immutable; no Any::Moose; 1; __END__ =head1 NAME Path::Dispatcher::Rule::Metadata - match path's metadata =head1 SYNOPSIS my $path = Path::Dispatcher::Path->new( path => '/REST/Ticket' metadata => { http_method => 'POST', }, ); my $rule = Path::Dispatcher::Rule::Metadata->new( field => 'http_method', matcher => Path::Dispatcher::Rule::Eq->new(string => 'POST'), ); $rule->run($path); =head1 DESCRIPTION Rules of this class match the metadata portion of a path. =head1 ATTRIBUTES =head2 field The metadata field/key name. =head2 matcher A L object for matching against the value of the field. =cut Path-Dispatcher-1.05/lib/Path/Dispatcher/Rule/Regex.pm000644 000765 000024 00000003044 12120355232 023112 0ustar00sartakstaff000000 000000 package Path::Dispatcher::Rule::Regex; use Any::Moose; extends 'Path::Dispatcher::Rule'; has regex => ( is => 'ro', isa => 'RegexpRef', required => 1, ); my $named_captures = $] > 5.010 ? eval 'sub { %+ }' : sub { }; sub _match { my $self = shift; my $path = shift; # davem++ http://www.nntp.perl.org/group/perl.perl5.porters/2013/03/msg200156.html if ($self->prefix) { eval q{$'}; } return unless my @positional = $path->path =~ $self->regex; my %named = $named_captures->(); my %extra; # only provide leftover if we need it. $' is slow, and it may be undef if ($self->prefix) { $extra{leftover} = eval q{$'}; delete $extra{leftover} if !defined($extra{leftover}); } return { positional_captures => \@positional, named_captures => \%named, %extra, } } __PACKAGE__->meta->make_immutable; no Any::Moose; 1; __END__ =head1 NAME Path::Dispatcher::Rule::Regex - predicate is a regular expression =head1 SYNOPSIS my $rule = Path::Dispatcher::Rule::Regex->new( regex => qr{^/comment(s?)/(\d+)$}, block => sub { display_comment(shift->pos(2)) }, ); =head1 DESCRIPTION Rules of this class use a regular expression to match against the path. =head1 ATTRIBUTES =head2 regex The regular expression to match against the path. It works just as you'd expect! The capture variables (C<$1>, C<$2>, etc) will be available in the match object as C<< ->pos(1) >> etc. C<$`>, C<$&>, and C<$'> are not restored. =cut Path-Dispatcher-1.05/lib/Path/Dispatcher/Rule/Sequence.pm000644 000765 000024 00000004331 12120355012 023604 0ustar00sartakstaff000000 000000 package Path::Dispatcher::Rule::Sequence; use Any::Moose; extends 'Path::Dispatcher::Rule'; with 'Path::Dispatcher::Role::Rules'; has delimiter => ( is => 'ro', isa => 'Str', default => ' ', ); sub _match_as_far_as_possible { my $self = shift; my $path = shift; my @tokens = $self->tokenize($path->path); my @rules = $self->rules; my @matched; while (@tokens && @rules) { my $rule = $rules[0]; my $token = $tokens[0]; last unless $rule->match($path->clone_path($token)); push @matched, $token; shift @rules; shift @tokens; } return (\@matched, \@tokens, \@rules); } sub _match { my $self = shift; my $path = shift; my ($matched, $tokens, $rules) = $self->_match_as_far_as_possible($path); return if @$rules; # didn't provide everything necessary return if @$tokens && !$self->prefix; # had tokens left over my $leftover = $self->untokenize(@$tokens); return { leftover => $leftover, positional_captures => $matched, }; } sub complete { my $self = shift; my $path = shift; my ($matched, $tokens, $rules) = $self->_match_as_far_as_possible($path); return if @$tokens > 1; # had tokens leftover return if !@$rules; # consumed all rules my $rule = shift @$rules; my $token = @$tokens ? shift @$tokens : ''; return map { $self->untokenize(@$matched, $_) } $rule->complete($path->clone_path($token)); } sub tokenize { my $self = shift; my $path = shift; return grep { length } split $self->delimiter, $path; } sub untokenize { my $self = shift; my @tokens = @_; return join $self->delimiter, grep { length } map { split $self->delimiter, $_ } @tokens; } __PACKAGE__->meta->make_immutable; no Any::Moose; 1; __END__ =head1 NAME Path::Dispatcher::Rule::Sequence - a sequence of rules =head1 SYNOPSIS =head1 DESCRIPTION This is basically a more robust and flexible version of L. Instead of a mish-mash of strings, regexes, and array references, a Sequence rule has just a list of other rules. =head1 ATTRIBUTES =head2 rules =head2 delimiter =cut Path-Dispatcher-1.05/lib/Path/Dispatcher/Rule/Tokens.pm000644 000765 000024 00000011311 12120355012 023273 0ustar00sartakstaff000000 000000 package Path::Dispatcher::Rule::Tokens; use Any::Moose; extends 'Path::Dispatcher::Rule'; has tokens => ( is => 'ro', isa => 'ArrayRef', auto_deref => 1, required => 1, ); has delimiter => ( is => 'ro', isa => 'Str', default => ' ', ); has case_sensitive => ( is => 'ro', isa => 'Bool', default => 1, ); sub _match_as_far_as_possible { my $self = shift; my $path = shift; my @got = $self->tokenize($path->path); my @expected = $self->tokens; my @matched; while (@got && @expected) { my $expected = $expected[0]; my $got = $got[0]; last unless $self->_match_token($got, $expected); push @matched, $got; shift @expected; shift @got; } return (\@matched, \@got, \@expected); } sub _match { my $self = shift; my $path = shift; my ($matched, $got, $expected) = $self->_match_as_far_as_possible($path); return if @$expected; # didn't provide everything necessary return if @$got && !$self->prefix; # had tokens left over my $leftover = $self->untokenize(@$got); return if !$matched; return { positional_captures => $matched, leftover => $leftover, }; } sub complete { my $self = shift; my $path = shift; my ($matched, $got, $expected) = $self->_match_as_far_as_possible($path); return if @$got > 1; # had tokens leftover return if !@$expected; # consumed all tokens my $next = shift @$expected; my $part = @$got ? shift @$got : ''; my @completions; for my $completion (ref($next) eq 'ARRAY' ? @$next : $next) { next if ref($completion); next unless substr($completion, 0, length($part)) eq $part; push @completions, $self->untokenize(@$matched, $completion); } return @completions; } sub _each_token { my $self = shift; my $got = shift; my $expected = shift; my $callback = shift; if (ref($expected) eq 'ARRAY') { for my $alternative (@$expected) { $self->_each_token($got, $alternative, $callback); } } elsif (!ref($expected) || ref($expected) eq 'Regexp') { $callback->($got, $expected); } else { die "Unexpected token '$expected'"; # the irony is not lost on me :) } } sub _match_token { my $self = shift; my $got = shift; my $expected = shift; my $matched = 0; $self->_each_token($got, $expected, sub { my ($g, $e) = @_; if (!ref($e)) { ($g, $e) = (lc $g, lc $e) if !$self->case_sensitive; $matched ||= $g eq $e; } elsif (ref($e) eq 'Regexp') { $matched ||= $g =~ $e; } }); return $matched; } sub tokenize { my $self = shift; my $path = shift; return grep { length } split $self->delimiter, $path; } sub untokenize { my $self = shift; my @tokens = @_; return join $self->delimiter, grep { length } map { split $self->delimiter, $_ } @tokens; } __PACKAGE__->meta->make_immutable; no Any::Moose; 1; __END__ =head1 NAME Path::Dispatcher::Rule::Tokens - predicate is a list of tokens =head1 SYNOPSIS my $rule = Path::Dispatcher::Rule::Tokens->new( tokens => [ "comment", "show", qr/^\d+$/ ], delimiter => '/', block => sub { display_comment(shift->pos(3)) }, ); $rule->match("/comment/show/25"); =head1 DESCRIPTION Rules of this class use a list of tokens to match the path. =head1 ATTRIBUTES =head2 tokens Each token can be a literal string, a regular expression, or a list of either (which are taken to mean alternations). For example, the tokens: [ 'ticket', [ 'show', 'display' ], [ qr/^\d+$/, qr/^#\w{3}/ ] ] first matches "ticket". Then, the next token must be "show" or "display". The final token must be a number or a pound sign followed by three word characters. The results are the tokens in the original string, as they were matched. If you have three tokens, then C<< match->pos(1) >> will be the string's first token ("ticket"), C<< match->pos(2) >> its second ("display"), and C<< match->pos(3) >> its third ("#AAA"). Capture groups inside a regex token are completely ignored. =head2 delimiter A string that is used to tokenize the path. The delimiter must be a string because prefix matches use C on unmatched tokens to return the leftover path. In the future this may be extended to support having a regex delimiter. The default is a space, but if you're matching URLs you probably want to change this to a slash. =head2 case_sensitive Decide whether the rule matching is case sensitive. Default is 1, case sensitive matching. =cut Path-Dispatcher-1.05/lib/Path/Dispatcher/Rule/Under.pm000644 000765 000024 00000006567 12120355012 023126 0ustar00sartakstaff000000 000000 package Path::Dispatcher::Rule::Under; use Any::Moose; use Any::Moose '::Util::TypeConstraints'; extends 'Path::Dispatcher::Rule'; with 'Path::Dispatcher::Role::Rules'; subtype 'Path::Dispatcher::PrefixRule' => as 'Path::Dispatcher::Rule' => where { $_->prefix } => message { "This rule ($_) does not match just prefixes!" }; has predicate => ( is => 'ro', isa => 'Path::Dispatcher::PrefixRule', ); sub match { my $self = shift; my $path = shift; my $prefix_match = $self->predicate->match($path) or return; my $leftover = $prefix_match->leftover; $leftover = '' if !defined($leftover); my $new_path = $path->clone_path($leftover); # Pop off @matches until we have a last rule that is not ::Chain # # A better technique than isa might be to use the concept of 'endpoint', 'midpoint', or 'anypoint' rules and # add a method to ::Rule that lets evaluate whether any rule is of the right kind (i.e. ->is_endpoint) # # Because the checking for ::Chain endpointedness is here, this means that outside of an ::Under, ::Chain behaves like # an ::Always (one that will always trigger next_rule if it's block is ran) # my @matches = map { $_->match( $new_path, extra_constructor_args => { parent => $prefix_match, }, ) } $self->rules; pop @matches while @matches && $matches[-1]->rule->isa('Path::Dispatcher::Rule::Chain'); return @matches; } sub complete { my $self = shift; my $path = shift; my $predicate = $self->predicate; my $prefix_match = $predicate->match($path) or return $predicate->complete($path); my $new_path = $path->clone_path($prefix_match->leftover); my $prefix = substr($path->path, 0, length($path->path) - length($new_path->path)); my @completions = map { $_->complete($new_path) } $self->rules; if ($predicate->can('untokenize')) { return map { $predicate->untokenize($prefix, $_) } @completions; } else { return map { "$prefix$_" } @completions; } } __PACKAGE__->meta->make_immutable; no Any::Moose; 1; __END__ =head1 NAME Path::Dispatcher::Rule::Under - rules under a predicate =head1 SYNOPSIS my $ticket = Path::Dispatcher::Rule::Tokens->new( tokens => [ 'ticket' ], prefix => 1, ); my $create = Path::Dispatcher::Rule::Tokens->new( tokens => [ 'create' ], block => sub { create_ticket() }, ); my $delete = Path::Dispatcher::Rule::Tokens->new( tokens => [ 'delete', qr/^\d+$/ ], block => sub { delete_ticket(shift->pos(2)) }, ); my $rule = Path::Dispatcher::Rule::Under->new( predicate => $ticket, rules => [ $create, $delete ], ); $rule->match("ticket create"); $rule->match("ticket delete 3"); =head1 DESCRIPTION Rules of this class have two-phase matching: if the predicate is matched, then the contained rules are matched. The benefit of this is less repetition of the predicate, both in terms of code and in matching it. =head1 ATTRIBUTES =head2 predicate A rule (which I match prefixes) whose match determines whether the contained rules are considered. The leftover path of the predicate is used as the path for the contained rules. =head2 rules A list of rules that will be try to be matched only if the predicate is matched. =cut Path-Dispatcher-1.05/lib/Path/Dispatcher/Role/Rules.pm000644 000765 000024 00000001553 12120355012 023123 0ustar00sartakstaff000000 000000 package Path::Dispatcher::Role::Rules; use Any::Moose '::Role'; has _rules => ( is => 'ro', isa => 'ArrayRef', init_arg => 'rules', default => sub { [] }, ); sub add_rule { my $self = shift; $_->isa('Path::Dispatcher::Rule') or confess "$_ is not a Path::Dispatcher::Rule" for @_; push @{ $self->{_rules} }, @_; } sub unshift_rule { my $self = shift; $_->isa('Path::Dispatcher::Rule') or confess "$_ is not a Path::Dispatcher::Rule" for @_; unshift @{ $self->{_rules} }, @_; } sub rules { @{ shift->{_rules} } } no Any::Moose; 1; __END__ =head1 NAME Path::Dispatcher::Role::Rules - "has a list of rules" =head1 DESCRIPTION Classes that compose this role get the following things: =head1 ATTRIBUTES =head2 _rules =head1 METHODS =head2 rules =head2 add_rule =cut Path-Dispatcher-1.05/inc/Module/000755 000765 000024 00000000000 12120355552 017045 5ustar00sartakstaff000000 000000 Path-Dispatcher-1.05/inc/Module/Install/000755 000765 000024 00000000000 12120355552 020453 5ustar00sartakstaff000000 000000 Path-Dispatcher-1.05/inc/Module/Install.pm000644 000765 000024 00000030135 12120355521 021007 0ustar00sartakstaff000000 000000 #line 1 package Module::Install; # For any maintainers: # The load order for Module::Install is a bit magic. # It goes something like this... # # IF ( host has Module::Install installed, creating author mode ) { # 1. Makefile.PL calls "use inc::Module::Install" # 2. $INC{inc/Module/Install.pm} set to installed version of inc::Module::Install # 3. The installed version of inc::Module::Install loads # 4. inc::Module::Install calls "require Module::Install" # 5. The ./inc/ version of Module::Install loads # } ELSE { # 1. Makefile.PL calls "use inc::Module::Install" # 2. $INC{inc/Module/Install.pm} set to ./inc/ version of Module::Install # 3. The ./inc/ version of Module::Install loads # } use 5.005; use strict 'vars'; use Cwd (); use File::Find (); use File::Path (); use vars qw{$VERSION $MAIN}; BEGIN { # All Module::Install core packages now require synchronised versions. # This will be used to ensure we don't accidentally load old or # different versions of modules. # This is not enforced yet, but will be some time in the next few # releases once we can make sure it won't clash with custom # Module::Install extensions. $VERSION = '1.06'; # Storage for the pseudo-singleton $MAIN = undef; *inc::Module::Install::VERSION = *VERSION; @inc::Module::Install::ISA = __PACKAGE__; } sub import { my $class = shift; my $self = $class->new(@_); my $who = $self->_caller; #------------------------------------------------------------- # all of the following checks should be included in import(), # to allow "eval 'require Module::Install; 1' to test # installation of Module::Install. (RT #51267) #------------------------------------------------------------- # Whether or not inc::Module::Install is actually loaded, the # $INC{inc/Module/Install.pm} is what will still get set as long as # the caller loaded module this in the documented manner. # If not set, the caller may NOT have loaded the bundled version, and thus # they may not have a MI version that works with the Makefile.PL. This would # result in false errors or unexpected behaviour. And we don't want that. my $file = join( '/', 'inc', split /::/, __PACKAGE__ ) . '.pm'; unless ( $INC{$file} ) { die <<"END_DIE" } Please invoke ${\__PACKAGE__} with: use inc::${\__PACKAGE__}; not: use ${\__PACKAGE__}; END_DIE # This reportedly fixes a rare Win32 UTC file time issue, but # as this is a non-cross-platform XS module not in the core, # we shouldn't really depend on it. See RT #24194 for detail. # (Also, this module only supports Perl 5.6 and above). eval "use Win32::UTCFileTime" if $^O eq 'MSWin32' && $] >= 5.006; # If the script that is loading Module::Install is from the future, # then make will detect this and cause it to re-run over and over # again. This is bad. Rather than taking action to touch it (which # is unreliable on some platforms and requires write permissions) # for now we should catch this and refuse to run. if ( -f $0 ) { my $s = (stat($0))[9]; # If the modification time is only slightly in the future, # sleep briefly to remove the problem. my $a = $s - time; if ( $a > 0 and $a < 5 ) { sleep 5 } # Too far in the future, throw an error. my $t = time; if ( $s > $t ) { die <<"END_DIE" } Your installer $0 has a modification time in the future ($s > $t). This is known to create infinite loops in make. Please correct this, then run $0 again. END_DIE } # Build.PL was formerly supported, but no longer is due to excessive # difficulty in implementing every single feature twice. if ( $0 =~ /Build.PL$/i ) { die <<"END_DIE" } Module::Install no longer supports Build.PL. It was impossible to maintain duel backends, and has been deprecated. Please remove all Build.PL files and only use the Makefile.PL installer. END_DIE #------------------------------------------------------------- # To save some more typing in Module::Install installers, every... # use inc::Module::Install # ...also acts as an implicit use strict. $^H |= strict::bits(qw(refs subs vars)); #------------------------------------------------------------- unless ( -f $self->{file} ) { foreach my $key (keys %INC) { delete $INC{$key} if $key =~ /Module\/Install/; } local $^W; require "$self->{path}/$self->{dispatch}.pm"; File::Path::mkpath("$self->{prefix}/$self->{author}"); $self->{admin} = "$self->{name}::$self->{dispatch}"->new( _top => $self ); $self->{admin}->init; @_ = ($class, _self => $self); goto &{"$self->{name}::import"}; } local $^W; *{"${who}::AUTOLOAD"} = $self->autoload; $self->preload; # Unregister loader and worker packages so subdirs can use them again delete $INC{'inc/Module/Install.pm'}; delete $INC{'Module/Install.pm'}; # Save to the singleton $MAIN = $self; return 1; } sub autoload { my $self = shift; my $who = $self->_caller; my $cwd = Cwd::cwd(); my $sym = "${who}::AUTOLOAD"; $sym->{$cwd} = sub { my $pwd = Cwd::cwd(); if ( my $code = $sym->{$pwd} ) { # Delegate back to parent dirs goto &$code unless $cwd eq $pwd; } unless ($$sym =~ s/([^:]+)$//) { # XXX: it looks like we can't retrieve the missing function # via $$sym (usually $main::AUTOLOAD) in this case. # I'm still wondering if we should slurp Makefile.PL to # get some context or not ... my ($package, $file, $line) = caller; die <<"EOT"; Unknown function is found at $file line $line. Execution of $file aborted due to runtime errors. If you're a contributor to a project, you may need to install some Module::Install extensions from CPAN (or other repository). If you're a user of a module, please contact the author. EOT } my $method = $1; if ( uc($method) eq $method ) { # Do nothing return; } elsif ( $method =~ /^_/ and $self->can($method) ) { # Dispatch to the root M:I class return $self->$method(@_); } # Dispatch to the appropriate plugin unshift @_, ( $self, $1 ); goto &{$self->can('call')}; }; } sub preload { my $self = shift; unless ( $self->{extensions} ) { $self->load_extensions( "$self->{prefix}/$self->{path}", $self ); } my @exts = @{$self->{extensions}}; unless ( @exts ) { @exts = $self->{admin}->load_all_extensions; } my %seen; foreach my $obj ( @exts ) { while (my ($method, $glob) = each %{ref($obj) . '::'}) { next unless $obj->can($method); next if $method =~ /^_/; next if $method eq uc($method); $seen{$method}++; } } my $who = $self->_caller; foreach my $name ( sort keys %seen ) { local $^W; *{"${who}::$name"} = sub { ${"${who}::AUTOLOAD"} = "${who}::$name"; goto &{"${who}::AUTOLOAD"}; }; } } sub new { my ($class, %args) = @_; delete $INC{'FindBin.pm'}; { # to suppress the redefine warning local $SIG{__WARN__} = sub {}; require FindBin; } # ignore the prefix on extension modules built from top level. my $base_path = Cwd::abs_path($FindBin::Bin); unless ( Cwd::abs_path(Cwd::cwd()) eq $base_path ) { delete $args{prefix}; } return $args{_self} if $args{_self}; $args{dispatch} ||= 'Admin'; $args{prefix} ||= 'inc'; $args{author} ||= ($^O eq 'VMS' ? '_author' : '.author'); $args{bundle} ||= 'inc/BUNDLES'; $args{base} ||= $base_path; $class =~ s/^\Q$args{prefix}\E:://; $args{name} ||= $class; $args{version} ||= $class->VERSION; unless ( $args{path} ) { $args{path} = $args{name}; $args{path} =~ s!::!/!g; } $args{file} ||= "$args{base}/$args{prefix}/$args{path}.pm"; $args{wrote} = 0; bless( \%args, $class ); } sub call { my ($self, $method) = @_; my $obj = $self->load($method) or return; splice(@_, 0, 2, $obj); goto &{$obj->can($method)}; } sub load { my ($self, $method) = @_; $self->load_extensions( "$self->{prefix}/$self->{path}", $self ) unless $self->{extensions}; foreach my $obj (@{$self->{extensions}}) { return $obj if $obj->can($method); } my $admin = $self->{admin} or die <<"END_DIE"; The '$method' method does not exist in the '$self->{prefix}' path! Please remove the '$self->{prefix}' directory and run $0 again to load it. END_DIE my $obj = $admin->load($method, 1); push @{$self->{extensions}}, $obj; $obj; } sub load_extensions { my ($self, $path, $top) = @_; my $should_reload = 0; unless ( grep { ! ref $_ and lc $_ eq lc $self->{prefix} } @INC ) { unshift @INC, $self->{prefix}; $should_reload = 1; } foreach my $rv ( $self->find_extensions($path) ) { my ($file, $pkg) = @{$rv}; next if $self->{pathnames}{$pkg}; local $@; my $new = eval { local $^W; require $file; $pkg->can('new') }; unless ( $new ) { warn $@ if $@; next; } $self->{pathnames}{$pkg} = $should_reload ? delete $INC{$file} : $INC{$file}; push @{$self->{extensions}}, &{$new}($pkg, _top => $top ); } $self->{extensions} ||= []; } sub find_extensions { my ($self, $path) = @_; my @found; File::Find::find( sub { my $file = $File::Find::name; return unless $file =~ m!^\Q$path\E/(.+)\.pm\Z!is; my $subpath = $1; return if lc($subpath) eq lc($self->{dispatch}); $file = "$self->{path}/$subpath.pm"; my $pkg = "$self->{name}::$subpath"; $pkg =~ s!/!::!g; # If we have a mixed-case package name, assume case has been preserved # correctly. Otherwise, root through the file to locate the case-preserved # version of the package name. if ( $subpath eq lc($subpath) || $subpath eq uc($subpath) ) { my $content = Module::Install::_read($subpath . '.pm'); my $in_pod = 0; foreach ( split //, $content ) { $in_pod = 1 if /^=\w/; $in_pod = 0 if /^=cut/; next if ($in_pod || /^=cut/); # skip pod text next if /^\s*#/; # and comments if ( m/^\s*package\s+($pkg)\s*;/i ) { $pkg = $1; last; } } } push @found, [ $file, $pkg ]; }, $path ) if -d $path; @found; } ##################################################################### # Common Utility Functions sub _caller { my $depth = 0; my $call = caller($depth); while ( $call eq __PACKAGE__ ) { $depth++; $call = caller($depth); } return $call; } # Done in evals to avoid confusing Perl::MinimumVersion eval( $] >= 5.006 ? <<'END_NEW' : <<'END_OLD' ); die $@ if $@; sub _read { local *FH; open( FH, '<', $_[0] ) or die "open($_[0]): $!"; my $string = do { local $/; }; close FH or die "close($_[0]): $!"; return $string; } END_NEW sub _read { local *FH; open( FH, "< $_[0]" ) or die "open($_[0]): $!"; my $string = do { local $/; }; close FH or die "close($_[0]): $!"; return $string; } END_OLD sub _readperl { my $string = Module::Install::_read($_[0]); $string =~ s/(?:\015{1,2}\012|\015|\012)/\n/sg; $string =~ s/(\n)\n*__(?:DATA|END)__\b.*\z/$1/s; $string =~ s/\n\n=\w+.+?\n\n=cut\b.+?\n+/\n\n/sg; return $string; } sub _readpod { my $string = Module::Install::_read($_[0]); $string =~ s/(?:\015{1,2}\012|\015|\012)/\n/sg; return $string if $_[0] =~ /\.pod\z/; $string =~ s/(^|\n=cut\b.+?\n+)[^=\s].+?\n(\n=\w+|\z)/$1$2/sg; $string =~ s/\n*=pod\b[^\n]*\n+/\n\n/sg; $string =~ s/\n*=cut\b[^\n]*\n+/\n\n/sg; $string =~ s/^\n+//s; return $string; } # Done in evals to avoid confusing Perl::MinimumVersion eval( $] >= 5.006 ? <<'END_NEW' : <<'END_OLD' ); die $@ if $@; sub _write { local *FH; open( FH, '>', $_[0] ) or die "open($_[0]): $!"; foreach ( 1 .. $#_ ) { print FH $_[$_] or die "print($_[0]): $!"; } close FH or die "close($_[0]): $!"; } END_NEW sub _write { local *FH; open( FH, "> $_[0]" ) or die "open($_[0]): $!"; foreach ( 1 .. $#_ ) { print FH $_[$_] or die "print($_[0]): $!"; } close FH or die "close($_[0]): $!"; } END_OLD # _version is for processing module versions (eg, 1.03_05) not # Perl versions (eg, 5.8.1). sub _version ($) { my $s = shift || 0; my $d =()= $s =~ /(\.)/g; if ( $d >= 2 ) { # Normalise multipart versions $s =~ s/(\.)(\d{1,3})/sprintf("$1%03d",$2)/eg; } $s =~ s/^(\d+)\.?//; my $l = $1 || 0; my @v = map { $_ . '0' x (3 - length $_) } $s =~ /(\d{1,3})\D?/g; $l = $l . '.' . join '', @v if @v; return $l + 0; } sub _cmp ($$) { _version($_[1]) <=> _version($_[2]); } # Cloned from Params::Util::_CLASS sub _CLASS ($) { ( defined $_[0] and ! ref $_[0] and $_[0] =~ m/^[^\W\d]\w*(?:::\w+)*\z/s ) ? $_[0] : undef; } 1; # Copyright 2008 - 2012 Adam Kennedy. Path-Dispatcher-1.05/inc/Module/Install/AutoManifest.pm000644 000765 000024 00000001257 12120355521 023411 0ustar00sartakstaff000000 000000 #line 1 use strict; use warnings; package Module::Install::AutoManifest; use Module::Install::Base; BEGIN { our $VERSION = '0.003'; our $ISCORE = 1; our @ISA = qw(Module::Install::Base); } sub auto_manifest { my ($self) = @_; return unless $Module::Install::AUTHOR; die "auto_manifest requested, but no MANIFEST.SKIP exists\n" unless -e "MANIFEST.SKIP"; if (-e "MANIFEST") { unlink('MANIFEST') or die "Can't remove MANIFEST: $!"; } $self->postamble(<<"END"); create_distdir: manifest_clean manifest distclean :: manifest_clean manifest_clean: \t\$(RM_F) MANIFEST END } 1; __END__ #line 48 #line 131 1; # End of Module::Install::AutoManifest Path-Dispatcher-1.05/inc/Module/Install/Base.pm000644 000765 000024 00000002147 12120355521 021663 0ustar00sartakstaff000000 000000 #line 1 package Module::Install::Base; use strict 'vars'; use vars qw{$VERSION}; BEGIN { $VERSION = '1.06'; } # Suspend handler for "redefined" warnings BEGIN { my $w = $SIG{__WARN__}; $SIG{__WARN__} = sub { $w }; } #line 42 sub new { my $class = shift; unless ( defined &{"${class}::call"} ) { *{"${class}::call"} = sub { shift->_top->call(@_) }; } unless ( defined &{"${class}::load"} ) { *{"${class}::load"} = sub { shift->_top->load(@_) }; } bless { @_ }, $class; } #line 61 sub AUTOLOAD { local $@; my $func = eval { shift->_top->autoload } or return; goto &$func; } #line 75 sub _top { $_[0]->{_top}; } #line 90 sub admin { $_[0]->_top->{admin} or Module::Install::Base::FakeAdmin->new; } #line 106 sub is_admin { ! $_[0]->admin->isa('Module::Install::Base::FakeAdmin'); } sub DESTROY {} package Module::Install::Base::FakeAdmin; use vars qw{$VERSION}; BEGIN { $VERSION = $Module::Install::Base::VERSION; } my $fake; sub new { $fake ||= bless(\@_, $_[0]); } sub AUTOLOAD {} sub DESTROY {} # Restore warning handler BEGIN { $SIG{__WARN__} = $SIG{__WARN__}->(); } 1; #line 159 Path-Dispatcher-1.05/inc/Module/Install/Can.pm000644 000765 000024 00000006157 12120355521 021517 0ustar00sartakstaff000000 000000 #line 1 package Module::Install::Can; use strict; use Config (); use ExtUtils::MakeMaker (); use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.06'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } # check if we can load some module ### Upgrade this to not have to load the module if possible sub can_use { my ($self, $mod, $ver) = @_; $mod =~ s{::|\\}{/}g; $mod .= '.pm' unless $mod =~ /\.pm$/i; my $pkg = $mod; $pkg =~ s{/}{::}g; $pkg =~ s{\.pm$}{}i; local $@; eval { require $mod; $pkg->VERSION($ver || 0); 1 }; } # Check if we can run some command sub can_run { my ($self, $cmd) = @_; my $_cmd = $cmd; return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd)); for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') { next if $dir eq ''; require File::Spec; my $abs = File::Spec->catfile($dir, $cmd); return $abs if (-x $abs or $abs = MM->maybe_command($abs)); } return; } # Can our C compiler environment build XS files sub can_xs { my $self = shift; # Ensure we have the CBuilder module $self->configure_requires( 'ExtUtils::CBuilder' => 0.27 ); # Do we have the configure_requires checker? local $@; eval "require ExtUtils::CBuilder;"; if ( $@ ) { # They don't obey configure_requires, so it is # someone old and delicate. Try to avoid hurting # them by falling back to an older simpler test. return $self->can_cc(); } # Do we have a working C compiler my $builder = ExtUtils::CBuilder->new( quiet => 1, ); unless ( $builder->have_compiler ) { # No working C compiler return 0; } # Write a C file representative of what XS becomes require File::Temp; my ( $FH, $tmpfile ) = File::Temp::tempfile( "compilexs-XXXXX", SUFFIX => '.c', ); binmode $FH; print $FH <<'END_C'; #include "EXTERN.h" #include "perl.h" #include "XSUB.h" int main(int argc, char **argv) { return 0; } int boot_sanexs() { return 1; } END_C close $FH; # Can the C compiler access the same headers XS does my @libs = (); my $object = undef; eval { local $^W = 0; $object = $builder->compile( source => $tmpfile, ); @libs = $builder->link( objects => $object, module_name => 'sanexs', ); }; my $result = $@ ? 0 : 1; # Clean up all the build files foreach ( $tmpfile, $object, @libs ) { next unless defined $_; 1 while unlink; } return $result; } # Can we locate a (the) C compiler sub can_cc { my $self = shift; my @chunks = split(/ /, $Config::Config{cc}) or return; # $Config{cc} may contain args; try to find out the program part while (@chunks) { return $self->can_run("@chunks") || (pop(@chunks), next); } return; } # Fix Cygwin bug on maybe_command(); if ( $^O eq 'cygwin' ) { require ExtUtils::MM_Cygwin; require ExtUtils::MM_Win32; if ( ! defined(&ExtUtils::MM_Cygwin::maybe_command) ) { *ExtUtils::MM_Cygwin::maybe_command = sub { my ($self, $file) = @_; if ($file =~ m{^/cygdrive/}i and ExtUtils::MM_Win32->can('maybe_command')) { ExtUtils::MM_Win32->maybe_command($file); } else { ExtUtils::MM_Unix->maybe_command($file); } } } } 1; __END__ #line 236 Path-Dispatcher-1.05/inc/Module/Install/Fetch.pm000644 000765 000024 00000004627 12120355521 022047 0ustar00sartakstaff000000 000000 #line 1 package Module::Install::Fetch; use strict; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.06'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } sub get_file { my ($self, %args) = @_; my ($scheme, $host, $path, $file) = $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return; if ( $scheme eq 'http' and ! eval { require LWP::Simple; 1 } ) { $args{url} = $args{ftp_url} or (warn("LWP support unavailable!\n"), return); ($scheme, $host, $path, $file) = $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return; } $|++; print "Fetching '$file' from $host... "; unless (eval { require Socket; Socket::inet_aton($host) }) { warn "'$host' resolve failed!\n"; return; } return unless $scheme eq 'ftp' or $scheme eq 'http'; require Cwd; my $dir = Cwd::getcwd(); chdir $args{local_dir} or return if exists $args{local_dir}; if (eval { require LWP::Simple; 1 }) { LWP::Simple::mirror($args{url}, $file); } elsif (eval { require Net::FTP; 1 }) { eval { # use Net::FTP to get past firewall my $ftp = Net::FTP->new($host, Passive => 1, Timeout => 600); $ftp->login("anonymous", 'anonymous@example.com'); $ftp->cwd($path); $ftp->binary; $ftp->get($file) or (warn("$!\n"), return); $ftp->quit; } } elsif (my $ftp = $self->can_run('ftp')) { eval { # no Net::FTP, fallback to ftp.exe require FileHandle; my $fh = FileHandle->new; local $SIG{CHLD} = 'IGNORE'; unless ($fh->open("|$ftp -n")) { warn "Couldn't open ftp: $!\n"; chdir $dir; return; } my @dialog = split(/\n/, <<"END_FTP"); open $host user anonymous anonymous\@example.com cd $path binary get $file $file quit END_FTP foreach (@dialog) { $fh->print("$_\n") } $fh->close; } } else { warn "No working 'ftp' program available!\n"; chdir $dir; return; } unless (-f $file) { warn "Fetching failed: $@\n"; chdir $dir; return; } return if exists $args{size} and -s $file != $args{size}; system($args{run}) if exists $args{run}; unlink($file) if $args{remove}; print(((!exists $args{check_for} or -e $args{check_for}) ? "done!" : "failed! ($!)"), "\n"); chdir $dir; return !$?; } 1; Path-Dispatcher-1.05/inc/Module/Install/GithubMeta.pm000644 000765 000024 00000002105 12120355521 023034 0ustar00sartakstaff000000 000000 #line 1 package Module::Install::GithubMeta; use strict; use warnings; use Cwd; use base qw(Module::Install::Base); use vars qw($VERSION); $VERSION = '0.22'; sub githubmeta { my $self = shift; return unless $Module::Install::AUTHOR; return unless _under_git(); return unless $self->can_run('git'); my $remote = shift || 'origin'; return unless my ($git_url) = `git remote show -n $remote` =~ /URL: (.*)$/m; return unless $git_url =~ /github\.com/; # Not a Github repository my $http_url = $git_url; $git_url =~ s![\w\-]+\@([^:]+):!git://$1/!; $http_url =~ s![\w\-]+\@([^:]+):!https://$1/!; $http_url =~ s!\.git$!/tree!; $self->repository( $git_url ); $self->homepage( $http_url ) unless $self->homepage(); return 1; } sub _under_git { return 1 if -e '.git'; my $cwd = getcwd; my $last = $cwd; my $found = 0; while (1) { chdir '..' or last; my $current = getcwd; last if $last eq $current; $last = $current; if ( -e '.git' ) { $found = 1; last; } } chdir $cwd; return $found; } 'Github'; __END__ #line 111 Path-Dispatcher-1.05/inc/Module/Install/Makefile.pm000644 000765 000024 00000027437 12120355521 022537 0ustar00sartakstaff000000 000000 #line 1 package Module::Install::Makefile; use strict 'vars'; use ExtUtils::MakeMaker (); use Module::Install::Base (); use Fcntl qw/:flock :seek/; use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.06'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } sub Makefile { $_[0] } my %seen = (); sub prompt { shift; # Infinite loop protection my @c = caller(); if ( ++$seen{"$c[1]|$c[2]|$_[0]"} > 3 ) { die "Caught an potential prompt infinite loop ($c[1]|$c[2]|$_[0])"; } # In automated testing or non-interactive session, always use defaults if ( ($ENV{AUTOMATED_TESTING} or -! -t STDIN) and ! $ENV{PERL_MM_USE_DEFAULT} ) { local $ENV{PERL_MM_USE_DEFAULT} = 1; goto &ExtUtils::MakeMaker::prompt; } else { goto &ExtUtils::MakeMaker::prompt; } } # Store a cleaned up version of the MakeMaker version, # since we need to behave differently in a variety of # ways based on the MM version. my $makemaker = eval $ExtUtils::MakeMaker::VERSION; # If we are passed a param, do a "newer than" comparison. # Otherwise, just return the MakeMaker version. sub makemaker { ( @_ < 2 or $makemaker >= eval($_[1]) ) ? $makemaker : 0 } # Ripped from ExtUtils::MakeMaker 6.56, and slightly modified # as we only need to know here whether the attribute is an array # or a hash or something else (which may or may not be appendable). my %makemaker_argtype = ( C => 'ARRAY', CONFIG => 'ARRAY', # CONFIGURE => 'CODE', # ignore DIR => 'ARRAY', DL_FUNCS => 'HASH', DL_VARS => 'ARRAY', EXCLUDE_EXT => 'ARRAY', EXE_FILES => 'ARRAY', FUNCLIST => 'ARRAY', H => 'ARRAY', IMPORTS => 'HASH', INCLUDE_EXT => 'ARRAY', LIBS => 'ARRAY', # ignore '' MAN1PODS => 'HASH', MAN3PODS => 'HASH', META_ADD => 'HASH', META_MERGE => 'HASH', PL_FILES => 'HASH', PM => 'HASH', PMLIBDIRS => 'ARRAY', PMLIBPARENTDIRS => 'ARRAY', PREREQ_PM => 'HASH', CONFIGURE_REQUIRES => 'HASH', SKIP => 'ARRAY', TYPEMAPS => 'ARRAY', XS => 'HASH', # VERSION => ['version',''], # ignore # _KEEP_AFTER_FLUSH => '', clean => 'HASH', depend => 'HASH', dist => 'HASH', dynamic_lib=> 'HASH', linkext => 'HASH', macro => 'HASH', postamble => 'HASH', realclean => 'HASH', test => 'HASH', tool_autosplit => 'HASH', # special cases where you can use makemaker_append CCFLAGS => 'APPENDABLE', DEFINE => 'APPENDABLE', INC => 'APPENDABLE', LDDLFLAGS => 'APPENDABLE', LDFROM => 'APPENDABLE', ); sub makemaker_args { my ($self, %new_args) = @_; my $args = ( $self->{makemaker_args} ||= {} ); foreach my $key (keys %new_args) { if ($makemaker_argtype{$key}) { if ($makemaker_argtype{$key} eq 'ARRAY') { $args->{$key} = [] unless defined $args->{$key}; unless (ref $args->{$key} eq 'ARRAY') { $args->{$key} = [$args->{$key}] } push @{$args->{$key}}, ref $new_args{$key} eq 'ARRAY' ? @{$new_args{$key}} : $new_args{$key}; } elsif ($makemaker_argtype{$key} eq 'HASH') { $args->{$key} = {} unless defined $args->{$key}; foreach my $skey (keys %{ $new_args{$key} }) { $args->{$key}{$skey} = $new_args{$key}{$skey}; } } elsif ($makemaker_argtype{$key} eq 'APPENDABLE') { $self->makemaker_append($key => $new_args{$key}); } } else { if (defined $args->{$key}) { warn qq{MakeMaker attribute "$key" is overriden; use "makemaker_append" to append values\n}; } $args->{$key} = $new_args{$key}; } } return $args; } # For mm args that take multiple space-seperated args, # append an argument to the current list. sub makemaker_append { my $self = shift; my $name = shift; my $args = $self->makemaker_args; $args->{$name} = defined $args->{$name} ? join( ' ', $args->{$name}, @_ ) : join( ' ', @_ ); } sub build_subdirs { my $self = shift; my $subdirs = $self->makemaker_args->{DIR} ||= []; for my $subdir (@_) { push @$subdirs, $subdir; } } sub clean_files { my $self = shift; my $clean = $self->makemaker_args->{clean} ||= {}; %$clean = ( %$clean, FILES => join ' ', grep { length $_ } ($clean->{FILES} || (), @_), ); } sub realclean_files { my $self = shift; my $realclean = $self->makemaker_args->{realclean} ||= {}; %$realclean = ( %$realclean, FILES => join ' ', grep { length $_ } ($realclean->{FILES} || (), @_), ); } sub libs { my $self = shift; my $libs = ref $_[0] ? shift : [ shift ]; $self->makemaker_args( LIBS => $libs ); } sub inc { my $self = shift; $self->makemaker_args( INC => shift ); } sub _wanted_t { } sub tests_recursive { my $self = shift; my $dir = shift || 't'; unless ( -d $dir ) { die "tests_recursive dir '$dir' does not exist"; } my %tests = map { $_ => 1 } split / /, ($self->tests || ''); require File::Find; File::Find::find( sub { /\.t$/ and -f $_ and $tests{"$File::Find::dir/*.t"} = 1 }, $dir ); $self->tests( join ' ', sort keys %tests ); } sub write { my $self = shift; die "&Makefile->write() takes no arguments\n" if @_; # Check the current Perl version my $perl_version = $self->perl_version; if ( $perl_version ) { eval "use $perl_version; 1" or die "ERROR: perl: Version $] is installed, " . "but we need version >= $perl_version"; } # Make sure we have a new enough MakeMaker require ExtUtils::MakeMaker; if ( $perl_version and $self->_cmp($perl_version, '5.006') >= 0 ) { # This previous attempted to inherit the version of # ExtUtils::MakeMaker in use by the module author, but this # was found to be untenable as some authors build releases # using future dev versions of EU:MM that nobody else has. # Instead, #toolchain suggests we use 6.59 which is the most # stable version on CPAN at time of writing and is, to quote # ribasushi, "not terminally fucked, > and tested enough". # TODO: We will now need to maintain this over time to push # the version up as new versions are released. $self->build_requires( 'ExtUtils::MakeMaker' => 6.59 ); $self->configure_requires( 'ExtUtils::MakeMaker' => 6.59 ); } else { # Allow legacy-compatibility with 5.005 by depending on the # most recent EU:MM that supported 5.005. $self->build_requires( 'ExtUtils::MakeMaker' => 6.36 ); $self->configure_requires( 'ExtUtils::MakeMaker' => 6.36 ); } # Generate the MakeMaker params my $args = $self->makemaker_args; $args->{DISTNAME} = $self->name; $args->{NAME} = $self->module_name || $self->name; $args->{NAME} =~ s/-/::/g; $args->{VERSION} = $self->version or die <<'EOT'; ERROR: Can't determine distribution version. Please specify it explicitly via 'version' in Makefile.PL, or set a valid $VERSION in a module, and provide its file path via 'version_from' (or 'all_from' if you prefer) in Makefile.PL. EOT if ( $self->tests ) { my @tests = split ' ', $self->tests; my %seen; $args->{test} = { TESTS => (join ' ', grep {!$seen{$_}++} @tests), }; } elsif ( $Module::Install::ExtraTests::use_extratests ) { # Module::Install::ExtraTests doesn't set $self->tests and does its own tests via harness. # So, just ignore our xt tests here. } elsif ( -d 'xt' and ($Module::Install::AUTHOR or $ENV{RELEASE_TESTING}) ) { $args->{test} = { TESTS => join( ' ', map { "$_/*.t" } grep { -d $_ } qw{ t xt } ), }; } if ( $] >= 5.005 ) { $args->{ABSTRACT} = $self->abstract; $args->{AUTHOR} = join ', ', @{$self->author || []}; } if ( $self->makemaker(6.10) ) { $args->{NO_META} = 1; #$args->{NO_MYMETA} = 1; } if ( $self->makemaker(6.17) and $self->sign ) { $args->{SIGN} = 1; } unless ( $self->is_admin ) { delete $args->{SIGN}; } if ( $self->makemaker(6.31) and $self->license ) { $args->{LICENSE} = $self->license; } my $prereq = ($args->{PREREQ_PM} ||= {}); %$prereq = ( %$prereq, map { @$_ } # flatten [module => version] map { @$_ } grep $_, ($self->requires) ); # Remove any reference to perl, PREREQ_PM doesn't support it delete $args->{PREREQ_PM}->{perl}; # Merge both kinds of requires into BUILD_REQUIRES my $build_prereq = ($args->{BUILD_REQUIRES} ||= {}); %$build_prereq = ( %$build_prereq, map { @$_ } # flatten [module => version] map { @$_ } grep $_, ($self->configure_requires, $self->build_requires) ); # Remove any reference to perl, BUILD_REQUIRES doesn't support it delete $args->{BUILD_REQUIRES}->{perl}; # Delete bundled dists from prereq_pm, add it to Makefile DIR my $subdirs = ($args->{DIR} || []); if ($self->bundles) { my %processed; foreach my $bundle (@{ $self->bundles }) { my ($mod_name, $dist_dir) = @$bundle; delete $prereq->{$mod_name}; $dist_dir = File::Basename::basename($dist_dir); # dir for building this module if (not exists $processed{$dist_dir}) { if (-d $dist_dir) { # List as sub-directory to be processed by make push @$subdirs, $dist_dir; } # Else do nothing: the module is already present on the system $processed{$dist_dir} = undef; } } } unless ( $self->makemaker('6.55_03') ) { %$prereq = (%$prereq,%$build_prereq); delete $args->{BUILD_REQUIRES}; } if ( my $perl_version = $self->perl_version ) { eval "use $perl_version; 1" or die "ERROR: perl: Version $] is installed, " . "but we need version >= $perl_version"; if ( $self->makemaker(6.48) ) { $args->{MIN_PERL_VERSION} = $perl_version; } } if ($self->installdirs) { warn qq{old INSTALLDIRS (probably set by makemaker_args) is overriden by installdirs\n} if $args->{INSTALLDIRS}; $args->{INSTALLDIRS} = $self->installdirs; } my %args = map { ( $_ => $args->{$_} ) } grep {defined($args->{$_} ) } keys %$args; my $user_preop = delete $args{dist}->{PREOP}; if ( my $preop = $self->admin->preop($user_preop) ) { foreach my $key ( keys %$preop ) { $args{dist}->{$key} = $preop->{$key}; } } my $mm = ExtUtils::MakeMaker::WriteMakefile(%args); $self->fix_up_makefile($mm->{FIRST_MAKEFILE} || 'Makefile'); } sub fix_up_makefile { my $self = shift; my $makefile_name = shift; my $top_class = ref($self->_top) || ''; my $top_version = $self->_top->VERSION || ''; my $preamble = $self->preamble ? "# Preamble by $top_class $top_version\n" . $self->preamble : ''; my $postamble = "# Postamble by $top_class $top_version\n" . ($self->postamble || ''); local *MAKEFILE; open MAKEFILE, "+< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!"; eval { flock MAKEFILE, LOCK_EX }; my $makefile = do { local $/; }; $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /; $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g; $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g; $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m; $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m; # Module::Install will never be used to build the Core Perl # Sometimes PERL_LIB and PERL_ARCHLIB get written anyway, which breaks # PREFIX/PERL5LIB, and thus, install_share. Blank them if they exist $makefile =~ s/^PERL_LIB = .+/PERL_LIB =/m; #$makefile =~ s/^PERL_ARCHLIB = .+/PERL_ARCHLIB =/m; # Perl 5.005 mentions PERL_LIB explicitly, so we have to remove that as well. $makefile =~ s/(\"?)-I\$\(PERL_LIB\)\1//g; # XXX - This is currently unused; not sure if it breaks other MM-users # $makefile =~ s/^pm_to_blib\s+:\s+/pm_to_blib :: /mg; seek MAKEFILE, 0, SEEK_SET; truncate MAKEFILE, 0; print MAKEFILE "$preamble$makefile$postamble" or die $!; close MAKEFILE or die $!; 1; } sub preamble { my ($self, $text) = @_; $self->{preamble} = $text . $self->{preamble} if defined $text; $self->{preamble}; } sub postamble { my ($self, $text) = @_; $self->{postamble} ||= $self->admin->postamble; $self->{postamble} .= $text if defined $text; $self->{postamble} } 1; __END__ #line 544 Path-Dispatcher-1.05/inc/Module/Install/ManifestSkip.pm000644 000765 000024 00000001557 12120355521 023412 0ustar00sartakstaff000000 000000 #line 1 ## # name: Module::Install::ManifestSkip # abstract: Generate a MANIFEST.SKIP file # author: Ingy döt Net # license: perl # copyright: 2010, 2011 # see: # - Module::Manifest::Skip package Module::Install::ManifestSkip; use 5.008001; use strict; use warnings; use base 'Module::Install::Base'; my $requires = " use Module::Manifest::Skip 0.10 (); "; our $VERSION = '0.20'; our $AUTHOR_ONLY = 1; my $skip_file = "MANIFEST.SKIP"; sub manifest_skip { my $self = shift; return unless $self->is_admin; eval $requires; die $@ if $@; print "Writing $skip_file\n"; open OUT, '>', $skip_file or die "Can't open $skip_file for output: $!";; print OUT Module::Manifest::Skip->new->text; close OUT; $self->clean_files('MANIFEST'); $self->clean_files($skip_file) if grep /^clean$/, @_; } 1; Path-Dispatcher-1.05/inc/Module/Install/Metadata.pm000644 000765 000024 00000043277 12120355521 022542 0ustar00sartakstaff000000 000000 #line 1 package Module::Install::Metadata; use strict 'vars'; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.06'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } my @boolean_keys = qw{ sign }; my @scalar_keys = qw{ name module_name abstract version distribution_type tests installdirs }; my @tuple_keys = qw{ configure_requires build_requires requires recommends bundles resources }; my @resource_keys = qw{ homepage bugtracker repository }; my @array_keys = qw{ keywords author }; *authors = \&author; sub Meta { shift } sub Meta_BooleanKeys { @boolean_keys } sub Meta_ScalarKeys { @scalar_keys } sub Meta_TupleKeys { @tuple_keys } sub Meta_ResourceKeys { @resource_keys } sub Meta_ArrayKeys { @array_keys } foreach my $key ( @boolean_keys ) { *$key = sub { my $self = shift; if ( defined wantarray and not @_ ) { return $self->{values}->{$key}; } $self->{values}->{$key} = ( @_ ? $_[0] : 1 ); return $self; }; } foreach my $key ( @scalar_keys ) { *$key = sub { my $self = shift; return $self->{values}->{$key} if defined wantarray and !@_; $self->{values}->{$key} = shift; return $self; }; } foreach my $key ( @array_keys ) { *$key = sub { my $self = shift; return $self->{values}->{$key} if defined wantarray and !@_; $self->{values}->{$key} ||= []; push @{$self->{values}->{$key}}, @_; return $self; }; } foreach my $key ( @resource_keys ) { *$key = sub { my $self = shift; unless ( @_ ) { return () unless $self->{values}->{resources}; return map { $_->[1] } grep { $_->[0] eq $key } @{ $self->{values}->{resources} }; } return $self->{values}->{resources}->{$key} unless @_; my $uri = shift or die( "Did not provide a value to $key()" ); $self->resources( $key => $uri ); return 1; }; } foreach my $key ( grep { $_ ne "resources" } @tuple_keys) { *$key = sub { my $self = shift; return $self->{values}->{$key} unless @_; my @added; while ( @_ ) { my $module = shift or last; my $version = shift || 0; push @added, [ $module, $version ]; } push @{ $self->{values}->{$key} }, @added; return map {@$_} @added; }; } # Resource handling my %lc_resource = map { $_ => 1 } qw{ homepage license bugtracker repository }; sub resources { my $self = shift; while ( @_ ) { my $name = shift or last; my $value = shift or next; if ( $name eq lc $name and ! $lc_resource{$name} ) { die("Unsupported reserved lowercase resource '$name'"); } $self->{values}->{resources} ||= []; push @{ $self->{values}->{resources} }, [ $name, $value ]; } $self->{values}->{resources}; } # Aliases for build_requires that will have alternative # meanings in some future version of META.yml. sub test_requires { shift->build_requires(@_) } sub install_requires { shift->build_requires(@_) } # Aliases for installdirs options sub install_as_core { $_[0]->installdirs('perl') } sub install_as_cpan { $_[0]->installdirs('site') } sub install_as_site { $_[0]->installdirs('site') } sub install_as_vendor { $_[0]->installdirs('vendor') } sub dynamic_config { my $self = shift; my $value = @_ ? shift : 1; if ( $self->{values}->{dynamic_config} ) { # Once dynamic we never change to static, for safety return 0; } $self->{values}->{dynamic_config} = $value ? 1 : 0; return 1; } # Convenience command sub static_config { shift->dynamic_config(0); } sub perl_version { my $self = shift; return $self->{values}->{perl_version} unless @_; my $version = shift or die( "Did not provide a value to perl_version()" ); # Normalize the version $version = $self->_perl_version($version); # We don't support the really old versions unless ( $version >= 5.005 ) { die "Module::Install only supports 5.005 or newer (use ExtUtils::MakeMaker)\n"; } $self->{values}->{perl_version} = $version; } sub all_from { my ( $self, $file ) = @_; unless ( defined($file) ) { my $name = $self->name or die( "all_from called with no args without setting name() first" ); $file = join('/', 'lib', split(/-/, $name)) . '.pm'; $file =~ s{.*/}{} unless -e $file; unless ( -e $file ) { die("all_from cannot find $file from $name"); } } unless ( -f $file ) { die("The path '$file' does not exist, or is not a file"); } $self->{values}{all_from} = $file; # Some methods pull from POD instead of code. # If there is a matching .pod, use that instead my $pod = $file; $pod =~ s/\.pm$/.pod/i; $pod = $file unless -e $pod; # Pull the different values $self->name_from($file) unless $self->name; $self->version_from($file) unless $self->version; $self->perl_version_from($file) unless $self->perl_version; $self->author_from($pod) unless @{$self->author || []}; $self->license_from($pod) unless $self->license; $self->abstract_from($pod) unless $self->abstract; return 1; } sub provides { my $self = shift; my $provides = ( $self->{values}->{provides} ||= {} ); %$provides = (%$provides, @_) if @_; return $provides; } sub auto_provides { my $self = shift; return $self unless $self->is_admin; unless (-e 'MANIFEST') { warn "Cannot deduce auto_provides without a MANIFEST, skipping\n"; return $self; } # Avoid spurious warnings as we are not checking manifest here. local $SIG{__WARN__} = sub {1}; require ExtUtils::Manifest; local *ExtUtils::Manifest::manicheck = sub { return }; require Module::Build; my $build = Module::Build->new( dist_name => $self->name, dist_version => $self->version, license => $self->license, ); $self->provides( %{ $build->find_dist_packages || {} } ); } sub feature { my $self = shift; my $name = shift; my $features = ( $self->{values}->{features} ||= [] ); my $mods; if ( @_ == 1 and ref( $_[0] ) ) { # The user used ->feature like ->features by passing in the second # argument as a reference. Accomodate for that. $mods = $_[0]; } else { $mods = \@_; } my $count = 0; push @$features, ( $name => [ map { ref($_) ? ( ref($_) eq 'HASH' ) ? %$_ : @$_ : $_ } @$mods ] ); return @$features; } sub features { my $self = shift; while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) { $self->feature( $name, @$mods ); } return $self->{values}->{features} ? @{ $self->{values}->{features} } : (); } sub no_index { my $self = shift; my $type = shift; push @{ $self->{values}->{no_index}->{$type} }, @_ if $type; return $self->{values}->{no_index}; } sub read { my $self = shift; $self->include_deps( 'YAML::Tiny', 0 ); require YAML::Tiny; my $data = YAML::Tiny::LoadFile('META.yml'); # Call methods explicitly in case user has already set some values. while ( my ( $key, $value ) = each %$data ) { next unless $self->can($key); if ( ref $value eq 'HASH' ) { while ( my ( $module, $version ) = each %$value ) { $self->can($key)->($self, $module => $version ); } } else { $self->can($key)->($self, $value); } } return $self; } sub write { my $self = shift; return $self unless $self->is_admin; $self->admin->write_meta; return $self; } sub version_from { require ExtUtils::MM_Unix; my ( $self, $file ) = @_; $self->version( ExtUtils::MM_Unix->parse_version($file) ); # for version integrity check $self->makemaker_args( VERSION_FROM => $file ); } sub abstract_from { require ExtUtils::MM_Unix; my ( $self, $file ) = @_; $self->abstract( bless( { DISTNAME => $self->name }, 'ExtUtils::MM_Unix' )->parse_abstract($file) ); } # Add both distribution and module name sub name_from { my ($self, $file) = @_; if ( Module::Install::_read($file) =~ m/ ^ \s* package \s* ([\w:]+) \s* ; /ixms ) { my ($name, $module_name) = ($1, $1); $name =~ s{::}{-}g; $self->name($name); unless ( $self->module_name ) { $self->module_name($module_name); } } else { die("Cannot determine name from $file\n"); } } sub _extract_perl_version { if ( $_[0] =~ m/ ^\s* (?:use|require) \s* v? ([\d_\.]+) \s* ; /ixms ) { my $perl_version = $1; $perl_version =~ s{_}{}g; return $perl_version; } else { return; } } sub perl_version_from { my $self = shift; my $perl_version=_extract_perl_version(Module::Install::_read($_[0])); if ($perl_version) { $self->perl_version($perl_version); } else { warn "Cannot determine perl version info from $_[0]\n"; return; } } sub author_from { my $self = shift; my $content = Module::Install::_read($_[0]); if ($content =~ m/ =head \d \s+ (?:authors?)\b \s* ([^\n]*) | =head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s* .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s* ([^\n]*) /ixms) { my $author = $1 || $2; # XXX: ugly but should work anyway... if (eval "require Pod::Escapes; 1") { # Pod::Escapes has a mapping table. # It's in core of perl >= 5.9.3, and should be installed # as one of the Pod::Simple's prereqs, which is a prereq # of Pod::Text 3.x (see also below). $author =~ s{ E<( (\d+) | ([A-Za-z]+) )> } { defined $2 ? chr($2) : defined $Pod::Escapes::Name2character_number{$1} ? chr($Pod::Escapes::Name2character_number{$1}) : do { warn "Unknown escape: E<$1>"; "E<$1>"; }; }gex; } elsif (eval "require Pod::Text; 1" && $Pod::Text::VERSION < 3) { # Pod::Text < 3.0 has yet another mapping table, # though the table name of 2.x and 1.x are different. # (1.x is in core of Perl < 5.6, 2.x is in core of # Perl < 5.9.3) my $mapping = ($Pod::Text::VERSION < 2) ? \%Pod::Text::HTML_Escapes : \%Pod::Text::ESCAPES; $author =~ s{ E<( (\d+) | ([A-Za-z]+) )> } { defined $2 ? chr($2) : defined $mapping->{$1} ? $mapping->{$1} : do { warn "Unknown escape: E<$1>"; "E<$1>"; }; }gex; } else { $author =~ s{E}{<}g; $author =~ s{E}{>}g; } $self->author($author); } else { warn "Cannot determine author info from $_[0]\n"; } } #Stolen from M::B my %license_urls = ( perl => 'http://dev.perl.org/licenses/', apache => 'http://apache.org/licenses/LICENSE-2.0', apache_1_1 => 'http://apache.org/licenses/LICENSE-1.1', artistic => 'http://opensource.org/licenses/artistic-license.php', artistic_2 => 'http://opensource.org/licenses/artistic-license-2.0.php', lgpl => 'http://opensource.org/licenses/lgpl-license.php', lgpl2 => 'http://opensource.org/licenses/lgpl-2.1.php', lgpl3 => 'http://opensource.org/licenses/lgpl-3.0.html', bsd => 'http://opensource.org/licenses/bsd-license.php', gpl => 'http://opensource.org/licenses/gpl-license.php', gpl2 => 'http://opensource.org/licenses/gpl-2.0.php', gpl3 => 'http://opensource.org/licenses/gpl-3.0.html', mit => 'http://opensource.org/licenses/mit-license.php', mozilla => 'http://opensource.org/licenses/mozilla1.1.php', open_source => undef, unrestricted => undef, restrictive => undef, unknown => undef, ); sub license { my $self = shift; return $self->{values}->{license} unless @_; my $license = shift or die( 'Did not provide a value to license()' ); $license = __extract_license($license) || lc $license; $self->{values}->{license} = $license; # Automatically fill in license URLs if ( $license_urls{$license} ) { $self->resources( license => $license_urls{$license} ); } return 1; } sub _extract_license { my $pod = shift; my $matched; return __extract_license( ($matched) = $pod =~ m/ (=head \d \s+ L(?i:ICEN[CS]E|ICENSING)\b.*?) (=head \d.*|=cut.*|)\z /xms ) || __extract_license( ($matched) = $pod =~ m/ (=head \d \s+ (?:C(?i:OPYRIGHTS?)|L(?i:EGAL))\b.*?) (=head \d.*|=cut.*|)\z /xms ); } sub __extract_license { my $license_text = shift or return; my @phrases = ( '(?:under )?the same (?:terms|license) as (?:perl|the perl (?:\d )?programming language)' => 'perl', 1, '(?:under )?the terms of (?:perl|the perl programming language) itself' => 'perl', 1, 'Artistic and GPL' => 'perl', 1, 'GNU general public license' => 'gpl', 1, 'GNU public license' => 'gpl', 1, 'GNU lesser general public license' => 'lgpl', 1, 'GNU lesser public license' => 'lgpl', 1, 'GNU library general public license' => 'lgpl', 1, 'GNU library public license' => 'lgpl', 1, 'GNU Free Documentation license' => 'unrestricted', 1, 'GNU Affero General Public License' => 'open_source', 1, '(?:Free)?BSD license' => 'bsd', 1, 'Artistic license 2\.0' => 'artistic_2', 1, 'Artistic license' => 'artistic', 1, 'Apache (?:Software )?license' => 'apache', 1, 'GPL' => 'gpl', 1, 'LGPL' => 'lgpl', 1, 'BSD' => 'bsd', 1, 'Artistic' => 'artistic', 1, 'MIT' => 'mit', 1, 'Mozilla Public License' => 'mozilla', 1, 'Q Public License' => 'open_source', 1, 'OpenSSL License' => 'unrestricted', 1, 'SSLeay License' => 'unrestricted', 1, 'zlib License' => 'open_source', 1, 'proprietary' => 'proprietary', 0, ); while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) { $pattern =~ s#\s+#\\s+#gs; if ( $license_text =~ /\b$pattern\b/i ) { return $license; } } return ''; } sub license_from { my $self = shift; if (my $license=_extract_license(Module::Install::_read($_[0]))) { $self->license($license); } else { warn "Cannot determine license info from $_[0]\n"; return 'unknown'; } } sub _extract_bugtracker { my @links = $_[0] =~ m#L<( https?\Q://rt.cpan.org/\E[^>]+| https?\Q://github.com/\E[\w_]+/[\w_]+/issues| https?\Q://code.google.com/p/\E[\w_\-]+/issues/list )>#gx; my %links; @links{@links}=(); @links=keys %links; return @links; } sub bugtracker_from { my $self = shift; my $content = Module::Install::_read($_[0]); my @links = _extract_bugtracker($content); unless ( @links ) { warn "Cannot determine bugtracker info from $_[0]\n"; return 0; } if ( @links > 1 ) { warn "Found more than one bugtracker link in $_[0]\n"; return 0; } # Set the bugtracker bugtracker( $links[0] ); return 1; } sub requires_from { my $self = shift; my $content = Module::Install::_readperl($_[0]); my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+(v?[\d\.]+)/mg; while ( @requires ) { my $module = shift @requires; my $version = shift @requires; $self->requires( $module => $version ); } } sub test_requires_from { my $self = shift; my $content = Module::Install::_readperl($_[0]); my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+([\d\.]+)/mg; while ( @requires ) { my $module = shift @requires; my $version = shift @requires; $self->test_requires( $module => $version ); } } # Convert triple-part versions (eg, 5.6.1 or 5.8.9) to # numbers (eg, 5.006001 or 5.008009). # Also, convert double-part versions (eg, 5.8) sub _perl_version { my $v = $_[-1]; $v =~ s/^([1-9])\.([1-9]\d?\d?)$/sprintf("%d.%03d",$1,$2)/e; $v =~ s/^([1-9])\.([1-9]\d?\d?)\.(0|[1-9]\d?\d?)$/sprintf("%d.%03d%03d",$1,$2,$3 || 0)/e; $v =~ s/(\.\d\d\d)000$/$1/; $v =~ s/_.+$//; if ( ref($v) ) { # Numify $v = $v + 0; } return $v; } sub add_metadata { my $self = shift; my %hash = @_; for my $key (keys %hash) { warn "add_metadata: $key is not prefixed with 'x_'.\n" . "Use appopriate function to add non-private metadata.\n" unless $key =~ /^x_/; $self->{values}->{$key} = $hash{$key}; } } ###################################################################### # MYMETA Support sub WriteMyMeta { die "WriteMyMeta has been deprecated"; } sub write_mymeta_yaml { my $self = shift; # We need YAML::Tiny to write the MYMETA.yml file unless ( eval { require YAML::Tiny; 1; } ) { return 1; } # Generate the data my $meta = $self->_write_mymeta_data or return 1; # Save as the MYMETA.yml file print "Writing MYMETA.yml\n"; YAML::Tiny::DumpFile('MYMETA.yml', $meta); } sub write_mymeta_json { my $self = shift; # We need JSON to write the MYMETA.json file unless ( eval { require JSON; 1; } ) { return 1; } # Generate the data my $meta = $self->_write_mymeta_data or return 1; # Save as the MYMETA.yml file print "Writing MYMETA.json\n"; Module::Install::_write( 'MYMETA.json', JSON->new->pretty(1)->canonical->encode($meta), ); } sub _write_mymeta_data { my $self = shift; # If there's no existing META.yml there is nothing we can do return undef unless -f 'META.yml'; # We need Parse::CPAN::Meta to load the file unless ( eval { require Parse::CPAN::Meta; 1; } ) { return undef; } # Merge the perl version into the dependencies my $val = $self->Meta->{values}; my $perl = delete $val->{perl_version}; if ( $perl ) { $val->{requires} ||= []; my $requires = $val->{requires}; # Canonize to three-dot version after Perl 5.6 if ( $perl >= 5.006 ) { $perl =~ s{^(\d+)\.(\d\d\d)(\d*)}{join('.', $1, int($2||0), int($3||0))}e } unshift @$requires, [ perl => $perl ]; } # Load the advisory META.yml file my @yaml = Parse::CPAN::Meta::LoadFile('META.yml'); my $meta = $yaml[0]; # Overwrite the non-configure dependency hashs delete $meta->{requires}; delete $meta->{build_requires}; delete $meta->{recommends}; if ( exists $val->{requires} ) { $meta->{requires} = { map { @$_ } @{ $val->{requires} } }; } if ( exists $val->{build_requires} ) { $meta->{build_requires} = { map { @$_ } @{ $val->{build_requires} } }; } return $meta; } 1; Path-Dispatcher-1.05/inc/Module/Install/Win32.pm000644 000765 000024 00000003403 12120355521 021707 0ustar00sartakstaff000000 000000 #line 1 package Module::Install::Win32; use strict; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.06'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } # determine if the user needs nmake, and download it if needed sub check_nmake { my $self = shift; $self->load('can_run'); $self->load('get_file'); require Config; return unless ( $^O eq 'MSWin32' and $Config::Config{make} and $Config::Config{make} =~ /^nmake\b/i and ! $self->can_run('nmake') ); print "The required 'nmake' executable not found, fetching it...\n"; require File::Basename; my $rv = $self->get_file( url => 'http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe', ftp_url => 'ftp://ftp.microsoft.com/Softlib/MSLFILES/Nmake15.exe', local_dir => File::Basename::dirname($^X), size => 51928, run => 'Nmake15.exe /o > nul', check_for => 'Nmake.exe', remove => 1, ); die <<'END_MESSAGE' unless $rv; ------------------------------------------------------------------------------- Since you are using Microsoft Windows, you will need the 'nmake' utility before installation. It's available at: http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe or ftp://ftp.microsoft.com/Softlib/MSLFILES/Nmake15.exe Please download the file manually, save it to a directory in %PATH% (e.g. C:\WINDOWS\COMMAND\), then launch the MS-DOS command line shell, "cd" to that directory, and run "Nmake15.exe" from there; that will create the 'nmake.exe' file needed by this module. You may then resume the installation process described in README. ------------------------------------------------------------------------------- END_MESSAGE } 1; Path-Dispatcher-1.05/inc/Module/Install/WriteAll.pm000644 000765 000024 00000002376 12120355521 022540 0ustar00sartakstaff000000 000000 #line 1 package Module::Install::WriteAll; use strict; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.06'; @ISA = qw{Module::Install::Base}; $ISCORE = 1; } sub WriteAll { my $self = shift; my %args = ( meta => 1, sign => 0, inline => 0, check_nmake => 1, @_, ); $self->sign(1) if $args{sign}; $self->admin->WriteAll(%args) if $self->is_admin; $self->check_nmake if $args{check_nmake}; unless ( $self->makemaker_args->{PL_FILES} ) { # XXX: This still may be a bit over-defensive... unless ($self->makemaker(6.25)) { $self->makemaker_args( PL_FILES => {} ) if -f 'Build.PL'; } } # Until ExtUtils::MakeMaker support MYMETA.yml, make sure # we clean it up properly ourself. $self->realclean_files('MYMETA.yml'); if ( $args{inline} ) { $self->Inline->write; } else { $self->Makefile->write; } # The Makefile write process adds a couple of dependencies, # so write the META.yml files after the Makefile. if ( $args{meta} ) { $self->Meta->write; } # Experimental support for MYMETA if ( $ENV{X_MYMETA} ) { if ( $ENV{X_MYMETA} eq 'JSON' ) { $self->Meta->write_mymeta_json; } else { $self->Meta->write_mymeta_yaml; } } return 1; } 1;