Raphaël ROULET > Net-GrowlClient-0.02 > Net::GrowlClient

Download:
Net-GrowlClient-0.02.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.02   Source  

NAME ^

Net::GrowlClient - Perl implementation of Growl Network Notification Protocol (Client Part)

SYNOPSIS ^

        use Net::GrowlClient;

DESCRIPTION ^

Net::GrowlClient provides an object interface to register applications and/or send notifications to Growl Servers using udp protocol.

CONSTRUCTOR ^

init ( [ARGS] )

Initialize a Net::GrowlClient Application with a Growl Server target. The constructor takes arguments, these arguments are in key-value pairs.

There is two groups of parameters, protocol parameters and registration parameters.

Protocols parameters are:

 CLIENT_PEER_HOST       Remote server address or name
 CLIENT_PEER_PORT       Remote UDP port to use
 CLIENT_PASSWORD        Server password (if needed)
 CLIENT_CRYPT           Determine if we AES128 encrypt (boolean) (NOT IMPLEMENTED IN v < 0.10)
 CLIENT_TYPE_REGISTRATION Determine if we authenticate and how (0 md5 2 sha 4 noauth)
 CLIENT_TYPE_NOTIFICATION Determine if we authenticate and how (1 md5 3 sha 5 noauth)

Registering an application within a Growl Server consist to tell the Server who we are, ie the name of the application, and what kind of message we will use. As an example, the application "NetMonitor.pl" would register as "Perl NetMonitor" and tell the server that it will use "Standard Message" and "Alert Message" as kind of notifications.

Registering the application is implicit (Constructor does it) but may be avoided if the application has already been registered within the Growl Server.

Registering parameters are:

 CLIENT_APPLICATION_NAME        Name to register
 CLIENT_NOTIFICATION_LIST       List of notification type (A Reference to an array) 
 CLIENT_SKIP_REGISTER           Do or Do not Register flag (boolean)

You can also define some global notify() options wich could be override with the notify() method

 CLIENT_TITLE           Notification title
 CLIENT_STICKY          Sticky flag (boolean)
 CLIENT_NOTIFICATION    Default Notification to use
 CLIENT_MESSAGE         Message
 CLIENT_PRIORITY        Priority flag 

METHOD ^

notify(args)

Once the object initialized, you can start sending notifications to the server with this method. A Notification has a title and a message witch is related to one of the different kind of messages defined in the constructor. It also has a priority and a sticky flag. Priority is a value from -2 to 2, 0 is a normal priority. Sticky notifications does not desappear themselves on the server screen and needs a user interaction, this could be useful for important messages. But take care about not all notification display styles support sticky notification. As an example the default Bezel style doesn't.

Parameters:

 application    Application name #Be careful and see below
 title          The title 
 message        The message
 priority       Priority flag
 sticky         Sticky flag
 notification   Kind of notification to use

DEFAULT VALUES ^

Default values should be overwritten but some exists:

 CLIENT_TYPE_REGISTRATION       => 4 #noauth
 CLIENT_TYPE_NOTIFICATION       => 5 #noauth
 CLIENT_CRYPT                   => FALSE #Do not crypt ( AES128 is NOT IMPLEMENTED IN v < 0.10)
 CLIENT_PASSWORD                => '' #nullstring <=> nopassword
 CLIENT_PEER_HOST               => 'localhost'
 CLIENT_PEER_PORT               => 9887
 CLIENT_APPLICATION_NAME        => 'Net::GrowlClient'
 CLIENT_NOTIFICATION_LIST       => ['Net::GrowlClient Notification']
 CLIENT_NOTIFICATION            => First element of CLIENT_NOTIFICATION_LIST 
 CLIENT_DEFAULT_TITLE           => 'Hello from Net::GrowlClient!'
 CLIENT_DEFAULT_MESSAGE         => "Yeah! It Works!\nThis is the default message."
 CLIENT_STICKY                  => FALSE
 CLIENT_SKIP_REGISTER           => FALSE
 CLIENT_PRIORITY                => 0 #Normal 

Notify Method use object parameters. They could be overwritten but keep in mind that application name and the notification list needs to be registered in order to be used with the notify() method.

COMMON USAGE ^

Usually, you just want to see your message on the server screen and don't care about wich application is sending the message. In this case You just have to set a GrowlClient object which use the default values. The identity will be 'Net::GrowlClient' and the notification 'Net::GrowlClient Notification'. This is the minimal but sufficient usage.

 use Net::GrowlClient;

 my $growl = Net::GrowlClient->init(
        'CLIENT_PEER_HOST'      => 'server.example.com'
        ) or die "$!\n";

 $growl->notify(
        'title' => 'Notification title',
        'message'       => "first line\nsecond line"
        );

ADVANCED USAGE ^

Using advanced features alow your application to have its own identity and notification list. This make possible to set specific preferences for this application in the Growl Control Panel on the server.

This example create a GrowlClient object for the application "Foo" with the server "server.example.com" using md5 auth. Register this application 'Foo' with its notification list. Send a sticky notification to with tho highest priority.

 use Net::GrowlClient;

 my $growl = Net::GrowlClient->init(
        'CLIENT_TYPE_REGISTRATION'      => 0, #md5 auth
        'CLIENT_TYPE_NOTIFICATION'      => 1, #md5 auth
        'CLIENT_CRYPT'                  => 0, #Do not crypt 
        'CLIENT_PASSWORD'               => 'secret',
        'CLIENT_PEER_HOST'              => 'server.example.com',
        'CLIENT_APPLICATION_NAME'       => 'Foo',
        'CLIENT_NOTIFICATION_LIST'      => ['Foo Normal', 'Foo Alert'] #The default is the first 'Foo Normal'.
        ) or die "$!\n";

 $growl->notify(
        'title'         => 'Notification title',
        'message'       => "first line\nsecond line",
        'notification'  => 'Foo Alert', #Specify we do not use the default notification.
        'priority'      => 2,
        'sticky'        => 1
        );

This example create a GrowlClient object for one or more application with are already registered and send messages to the server from Application 1 and Application 2. This use sha256 auth method.

use Net::GrowlClient;

 my $growl = Net::GrowlClient->init(
        'CLIENT_TYPE_REGISTRATION'      => 2, #sha auth
        'CLIENT_TYPE_NOTIFICATION'      => 3, #sha auth
        'CLIENT_PASSWORD'               => 'secret',
        'CLIENT_PEER_HOST'              => 'server.example.com',
        ) or die "$!\n";
        
 $growl->notify(
        'title'         => 'Notification title',
        'message'       => "first line\nsecond line",
        'notification'  => 'An Application 1 Notification',
        'application'   => 'Application 1 wich is registered'
        );

 $growl->notify(
        'title'         => 'Notification title',
        'message'       => "first line\nsecond line",
        'notification'  => 'An Application 2 Notification', 
        'application'   => 'Application 2 wich is registered'
        );

MISSING THINGS ^

There is still some capabilities missing in this growl network client protocol implementation.

AUTHOR ^

Raphael Roulet. Please report all bugs to <modules@perl-auvergne.com> or <castor@cpan.org>.

syntax highlighting: