blib/lib/POE/Component/Growl.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 # ===========================================================================
2 # POE::Component::Growl - version 1.00 - 31 Jul 2005
3 #
4 # Growl notification dispatcher for POE
5 #
6 # Author: Alessandro Ranellucci <aar@cpan.org>
7 # Copyright (c) 2005 - All Rights Reserved.
8 #
9 # See below for documentation.
10 #Ê
11  
12 package POE::Component::Growl;
13  
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 0 ▶use Mac::Growl ':all';
Subroutine BEGIN: called CC=1 SCAR=2.6
19 use POE;
20  
21 $VERSION = '1.00';
22  
23 # object fields ("SF" stands for "self")
24 sub SF_ALIAS () { 0 }
25 sub SF_APPNAME () { 1 }
26 sub SF_NOTIF () { 2 }
27  
28 sub spawn {
29 my $type = shift;
30 croak "$type requires an even number of parameters" if @_ % 2;
31 my %params = @_;
32
33 # let's check params
34 my $alias = delete $params{Alias} || 'Growl';
35 my $appname = delete $params{AppName} || croak("Missing AppName parameter");
36 my $notif = delete $params{Notifications} || croak("Missing Notifications parameter");
37 my $defaultnotif = delete $params{DefaultNotifications} || $notif;
38 my $icon = delete $params{IconOfApp} || undef;
39 croak("Unknown parameters: ", join(', ', sort keys %params))
40 if scalar keys %params;
41
42 # register our app with Mac::Growl
43 RegisterNotifications($appname, $notif, $defaultnotif, $icon);
44 my $self = bless [
45 $alias,
46 $appname,
47 $notif
48 ], $type;
49
50 # register session with POE
51 POE::Session->create(
52 object_states => [
53 $self => {
54 _start => '_start',
55 post => 'post'
56 }
57 ]
58 );
59
60 return $self;
61 }
62  
63 sub _start {
64 my ($object, $kernel) = @_[OBJECT, KERNEL];
65 $kernel->alias_set( $object->[SF_ALIAS] );
66 }
67  
68 sub post {
69 my ($object, $kernel, $not) = @_[OBJECT, KERNEL, ARG0];
70 $object->notify($not);
71 }
72  
73 sub notify {
74 my ($self, $not) = @_;
75
76 &PostNotification(
77 $self->[SF_APPNAME],
78 @$not{ qw/name title descr/ },
79 map { $not->{$_} || 0 } qw/sticky priority/,
80 $not->{imagepath}
81 );
82 }
83  
84 1;
85  
86 __END__
↑ Summary