File: Shell.pm

package info (click to toggle)
libpath-router-perl 0.15-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 276 kB
  • sloc: perl: 1,863; makefile: 2
file content (118 lines) | stat: -rw-r--r-- 2,364 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package Path::Router::Shell;
our $AUTHORITY = 'cpan:STEVAN';
$Path::Router::Shell::VERSION = '0.15';
use Term::ReadLine  1.11;
use Types::Standard 1.000005 qw(InstanceOf);
use Data::Dumper    2.154;

use Moo              2.000001;
use namespace::clean 0.23;
# ABSTRACT: An interactive shell for testing router configurations

has 'router' => (
    is       => 'ro',
    isa      => InstanceOf['Path::Router'],
    required => 1,
);

sub shell {
    my $self = shift;

    my $term = Term::ReadLine->new(__PACKAGE__);
    my $OUT = $term->OUT || \*STDOUT;

    while ( defined ($_ = $term->readline("> ")) ) {
        chomp;
        return if /[qQ]/;
        my $map = $self->router->match($_);
        if ($map) {
            print $OUT Dumper $map;
            print $OUT "Round-trip URI is : " . $self->router->uri_for(%$map),
        }
        else {
            print $OUT "No match for $_\n";
        }
        $term->addhistory($_) if /\S/;
    }
}


1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Path::Router::Shell - An interactive shell for testing router configurations

=head1 VERSION

version 0.15

=head1 SYNOPSIS

  #!/usr/bin/perl

  use strict;
  use warnings;

  use My::App::Router;
  use Path::Router::Shell;

  Path::Router::Shell->new(router => My::App::Router->new)->shell;

=head1 DESCRIPTION

This is a tool for helping test the routing in your applications, so
you simply write a small script like showing in the SYNOPSIS and then
you can use it to test new routes or debug routing issues, etc etc etc.

=head1 METHODS

=over 4

=item B<new (router => $router)>

=item B<router>

=item B<shell>

=item B<meta>

=back

=head1 BUGS

All complex software has bugs lurking in it, and this module is no
exception. If you find a bug please either email me, or add the bug
to cpan-RT.

=head1 AUTHOR

Stevan Little E<lt>stevan@cpan.orgE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright 2008-2011 Infinity Interactive, Inc.

L<http://www.iinteractive.com>

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=head1 AUTHOR

Stevan Little <stevan@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by Infinity Interactive.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut