File Coverage

blib/lib/Log/Dispatch/DesktopNotification.pm
Criterion Covered Total %
statement 22 27 81.4
branch 2 6 33.3
condition 1 3 33.3
subroutine 7 7 100.0
pod 2 2 100.0
total 34 45 75.5


line stmt bran cond sub pod time code
1 1     1   39941 use strict;
  1         3  
  1         38  
2 1     1   6 use warnings;
  1         1  
  1         55  
3              
4             package Log::Dispatch::DesktopNotification;
5              
6 1     1   468151 use Module::Load qw/load/;
  1         1444  
  1         8  
7 1     1   177680 use Module::Load::Conditional qw/can_load/;
  1         53988  
  1         76  
8 1     1   1122 use namespace::clean;
  1         45133  
  1         8  
9              
10             our $VERSION = '0.01';
11              
12             =head1 NAME
13              
14             Log::Dispatch::DesktopNotification - Send log messages to a desktop notification system
15              
16             =head1 SYNOPSIS
17              
18             my $notify = Log::Dispatch::DesktopNotification->new(
19             name => 'notify',
20             min_level => 'debug',
21             app_name => 'MyApp',
22             );
23              
24             =head1 METHODS
25              
26             =head2 new
27              
28             Creates a new Log::Dispatch output that can be used to graphically notify a
29             user on this system. Uses C<output_class> and calls C<new> on the returned
30             class, passing along all arguments.
31              
32             =cut
33              
34             sub new {
35 1     1 1 17 my ($class, @args) = @_;
36 1         5 return $class->output_class->new(@args);
37             }
38              
39             =head2 output_class
40              
41             Returns the name of a Log::Dispatch::Output class that's suitable to
42             graphically notify a user on the current system.
43              
44             On MacOS X that'll be Log::Dispatch::MacGrowl. On other systems
45             Log::Dispatch::Gtk2::Notify will be returned if it's available and usable.
46             Otherwise Log::Dispatch::Null will be returned.
47              
48             =cut
49              
50             sub output_class {
51 1 50   1 1 7 if ($^O eq 'darwin') {
52 0         0 my $mod = 'Log::Dispatch::MacGrowl';
53 0         0 load $mod; return $mod;
  0         0  
54             }
55              
56 1 50 33     8 if (can_load(modules => { Gtk2 => undef }) && Gtk2->init_check) {
57 0         0 my $mod = 'Log::Dispatch::Gtk2::Notify';
58 0 0       0 return $mod if can_load(modules => { $mod => undef });
59             }
60              
61 1         719 my $mod = 'Log::Dispatch::Null';
62 1         5 load $mod; return $mod;
  1         16750  
63             }
64              
65             =head1 BUGS
66              
67             Currently only supports Mac OS X and systems on which notification-daemon is
68             available (most *N*Xes).
69              
70             =head1 SEE ALSO
71              
72             L<Log::Dispatch>, L<Log::Dispatch::Gtk2::Notify>, L<Log::Dispatch::MacGrowl>,
73             L<Log::Dispatch::Null>
74              
75             =head1 AUTHOR
76              
77             Florian Ragwitz E<lt>rafl@debian.orgE<gt>
78              
79             =head1 COPYRIGHT AND LICENSE
80              
81             This software is copyright (c) 2009 by Florian Ragwitz.
82              
83             This is free software; you can redistribute it and/or modify it under the same
84             terms as perl itself.
85              
86             =cut
87              
88             1;