Jaipo/Notify/LibNotify.pm

filter: Statementstmt 100% 12 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 16 / 16 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Jaipo/Filter.pm ↑ Summary
1 package Jaipo::Notify::LibNotify;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 #~ use Smart::Comments;
6 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use base qw(Desktop::Notify);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =encoding utf8
10  
11 =head1 NAME
12  
13 Jaipo::Notify::LibNotify - A easy-to-use interface to show desktop notifications with libnotify.
14  
15  
16 =head1 SYNOPSIS
17  
18 Jaipo::Notify::LibNotify is a easy-to-use interface to show desktop notifications with libnotify.
19 It doesn't use libnotify directly, but talking to libnotify via dbus.
20  
21  
22 use Jaipo::Notify::LibNotify;
23  
24 my $notify = Jaipo::Notify::LibNotify->new();
25
26 # yell for Service Notify.
27 $notify->yell('Cannot connect to M$-Mi$roBlo$: $!');
28  
29 # display for message displaying.
30 $notify->display("From Mr.Right: Hello Darling. How are you today?");
31
32 # pop_box for message displaying.
33 $notify->pop_box("Are you using M$ windows without buying license?");
34
35 # get current timeout setting
36 print Data::Dumper $notify->timeout;
37  
38 # set yell timeout to 10 seconds. default is 5.
39 $notify->timeout("yell" => 10);
40  
41 # set display timeout to 5 seconds. default is 3.
42 $notify->timeout("yell" => 5);
43  
44 =head1 FUNCTIONS
45  
46 =head2 new
47  
48 Return a object which talks to libnotify via dbus.
49  
50 =cut
51  
52 sub new {
53 my $class = shift;
54 print Dumper $class;
55 my $self = Desktop::Notify->new(@_);
56 bless $self, $class;
57 $self->{timeout_yell} = 5000;
58 $self->{timeout_display} = 3000;
59 return $self;
60 }
61  
62 =head2 yell
63  
64 yell for Service Notify.
65 Pops a notification with title "Jaipo Service Notify" and the given message content from you.
66  
67 =cut
68  
69 sub yell {
70 my ($self, $msg) = @_;
71 $self->create(
72 "summary" => 'Jaipo Service Notify',
73 "body" => $msg,
74 "timeout" => $self->{timeout_yell},
75 )->show();
76 }
77  
78 =head2 display
79  
80 display for message displaying.
81 Pops a notification with title "You've Got Message!" and the given message content from you.
82  
83 =cut
84  
85 sub display {
86 my ($self, $msg) = @_;
87 #~ $self->SUPER::display("Name", @args);
88 $self->create(
89 "summary" => "Jaipo: You've Got Message!",
90 "body" => $msg,
91 "timeout" => $self->{timeout_display},
92 )->show();
93 }
94  
95 =head2 pop_box
96  
97 pop_box for special message displaying.
98 Pops a window box with title "Pop!" and the given message content from you.
99  
100 =cut
101  
102 sub pop_box {
103 my ($self, $msg) = @_;
104 #~ $self->SUPER::display("Name", @args);
105 $self->create(
106 "summary" => "Jaipo: Pop!",
107 "body" => $msg,
108 #~ "timeout" => $self->{timeout_display},
109 )->show();
110 }
111  
112 =head2 timeout
113  
114 timeout for changing/getting the current timeout value.
115  
116  
117 =cut
118  
119 sub timeout {
120 my $self = shift;
121 my %timeout = (
122 "timeout_yell" => $self->{timeout_yell} / 1000,
123 "timeout_display" => $self->{timeout_display} / 1000,
124 );
125
126 if (not @_) {
127 # do nothing
128 }elsif ( $_[0] eq "yell" ) {
129 $self->{timeout_yell} = $_[1] * 1000;
130 } elsif ( $_[0] eq "display" ) {
131 $self->{timeout_display} = $_[1] * 1000;
132 }
133 return \%timeout;
134 }
135  
136 =head1 AUTHOR
137  
138 BlueT - Matthew Lien - 練喆明, C<< <BlueT at BlueT.org> >>
139  
140 =head1 BUGS
141  
142 Please report any bugs or feature requests to C<bug-jaipo-notify-libnotify at rt.cpan.org>, or through
143 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Jaipo-Notify-LibNotify>. I will be notified, and then you'll
144 automatically be notified of progress on your bug as I make changes.
145  
146  
147  
148  
149 =head1 SUPPORT
150  
151 You can find documentation for this module with the perldoc command.
152  
153 perldoc Jaipo::Notify::LibNotify
154  
155  
156 You can also look for information at:
157  
158 =over 4
159  
160 =item * RT: CPAN's request tracker
161  
162 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Jaipo-Notify-LibNotify>
163  
164 =item * AnnoCPAN: Annotated CPAN documentation
165  
166 L<http://annocpan.org/dist/Jaipo-Notify-LibNotify>
167  
168 =item * CPAN Ratings
169  
170 L<http://cpanratings.perl.org/d/Jaipo-Notify-LibNotify>
171  
172 =item * Search CPAN
173  
174 L<http://search.cpan.org/dist/Jaipo-Notify-LibNotify>
175  
176 =back
177  
178  
179 =head1 ACKNOWLEDGEMENTS
180  
181  
182 =head1 COPYRIGHT & LICENSE
183  
184 Copyright 2009 BlueT - Matthew Lien - 練喆明, all rights reserved.
185  
186 This program is free software; you can redistribute it and/or modify it
187 under the same terms as Perl itself.
188  
189  
190 =cut
191  
192 1; # End of Jaipo::Notify::LibNotify
« Jaipo/Filter.pm ↑ Summary