File Coverage

blib/lib/Dancer/Logger/Spinner.pm
Criterion Covered Total %
statement 10 10 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 14 100.0


line stmt bran cond sub pod time code
1 2     2   138336 use strict;
  2         8  
  2         556  
2 2     2   16 use warnings;
  2         5  
  2         163  
3             package Dancer::Logger::Spinner;
4             BEGIN {
5 2     2   54 $Dancer::Logger::Spinner::VERSION = '0.02';
6             }
7             # ABSTRACT: Show a spinner in the console on Dancer log messages!
8              
9 2     2   12 use base 'Dancer::Logger::Abstract';
  2         4  
  2         19569  
10              
11             sub init {
12             my $self = shift;
13             $self->{'spinner_chars'} = [ '\\', '|', '/', '-', 'x' ];
14             $self->{'spinner_count'} = 0;
15             }
16              
17             sub _log {
18             my $self = shift;
19             $self->advance_spinner();
20             }
21              
22             sub advance_spinner {
23             my $self = shift;
24             my $count = $self->{'spinner_count'};
25             my @chars = @{ $self->{'spinner_chars'} };
26              
27             # these chars lifted from Brandon L. Black's Term::Spinner
28             print STDERR "\010 \010";
29             print STDERR $chars[$count];
30              
31             # if we reached over the array end, let's get back to the start
32             ++$count > $#chars and $count = 0;
33              
34             # increment the counter and update the hash
35             $self->{'spinner_count'} = $count;
36             }
37              
38             sub DESTROY {
39             print STDERR "\n";
40             }
41              
42             1;
43              
44              
45              
46             =pod
47              
48             =head1 NAME
49              
50             Dancer::Logger::Spinner - Show a spinner in the console on Dancer log messages!
51              
52             =head1 VERSION
53              
54             version 0.02
55              
56             =head1 SYNOPSIS
57              
58             # in your Dancer app:
59             setting logger => 'spinner';
60              
61             # or in your Dancer config file:
62             logger: 'spinner'
63              
64             Et voila!
65              
66             =head1 DESCRIPTION
67              
68             When using this logger and running your application in the terminal, you will
69             see a text spinner running on each message it gets. If you have a page with a
70             lot of request, and they will come in fast, you'll see the spinner running. If
71             you have an app with very little requests in each page or if it is slow, the
72             spinner will run slowly.
73              
74             Each request matches another rotation of the spinner.
75              
76             =head1 SUBROUTINES/METHODS
77              
78             =head2 init
79              
80             Sets the spinner's characters and position.
81              
82             =head2 advance_spinner
83              
84             Advanced the spinner onefold by cleaning a terminal line and printing the next
85             spinner position.
86              
87             =head2 _log
88              
89             Gets a message to log and calls C.
90              
91             =head1 SEE ALSO
92              
93             The Dancer Advent Calendar 2010.
94              
95             =head1 AUTHOR
96              
97             Sawyer X
98              
99             =head1 COPYRIGHT AND LICENSE
100              
101             This software is copyright (c) 2010 by Sawyer X.
102              
103             This is free software; you can redistribute it and/or modify it under
104             the same terms as the Perl 5 programming language system itself.
105              
106             =cut
107              
108              
109             __END__