WebService::Rollbar::Notifier - send messages to www.rollbar.com service
use WebService::Rollbar::Notifier; my $roll = WebService::Rollbar::Notifier->new( access_token => 'YOUR_post_server_item_ACCESS_TOKEN', ); $roll->debug("Testing example stuff!", # this is some optional, abitrary data we're sending { foo => 'bar', caller => scalar(caller()), meow => { mew => { bars => [qw/1 2 3 4 5 /], }, }, });
This Perl module allows for blocking and non-blocking way to send messages to www.rollbar.com service.
->new()
my $roll = WebService::Rollbar::Notifier->new( access_token => 'YOUR_post_server_item_ACCESS_TOKEN', # all these are optional; defaults shown: environment => 'production', code_version => undef, callback => sub {}, );
Creates and returns new WebService::Rollbar::Notifier object. Takes arguments as key/value pairs:
WebService::Rollbar::Notifier
access_token
my $roll = WebService::Rollbar::Notifier->new( access_token => 'YOUR_post_server_item_ACCESS_TOKEN', );
Mandatory. This is your post_server_item project access token.
post_server_item
environment
my $roll = WebService::Rollbar::Notifier->new( ... environment => 'production', );
Optional. Takes a string up to 255 characters long. Specifies the environment we're messaging from. Defaults to production.
production
code_version
my $roll = WebService::Rollbar::Notifier->new( ... code_version => undef, );
Optional. By default is not specified. Takes a string up to 40 characters long. Describes the version of the application code. Rollbar understands these formats: semantic version (e.g. 2.1.12), integer (e.g. 45), git SHA (e.g. 3da541559918a808c2402bba5012f6c60b27661c).
2.1.12
45
3da541559918a808c2402bba5012f6c60b27661c
callback
# do nothing in the callback; this is default my $roll = WebService::Rollbar::Notifier->new( ... callback => sub {}, ); # perform a blocking call my $roll = WebService::Rollbar::Notifier->new( ... callback => undef, ); # non-blocking; do something usefull in the callback my $roll = WebService::Rollbar::Notifier->new( ... callback => sub { my ( $ua, $tx ) = @_; say $tx->res->body; }, );
Optional. Takes undef or a subref as a value. Defaults to a null subref. If set to undef, notifications to www.rollbar.com will be blocking, otherwise non-blocking, with the callback subref called after a request completes. The subref will receive in its @_ the Mojo::UserAgent object that performed the call and Mojo::Transaction::HTTP object with the response.
undef
@_
notify
$roll->notify('debug', "Message to send", { any => 'custom', optional => 'data', to => [qw/send goes here/], }); # if we're doing blocking calls, then return value will be # the response JSON use JSON::MaybeXS; $roll->callback(undef); my $json_response = $roll->notify('debug', "Message to send"); say decode_json($json_response;);
Takes two mandatory and one optional arguments. Always returns true value if we're making non-blocking calls (see callback argument to constructor). Otherwise, returns the response as JSON string. The arguments are:
$roll->notify('debug', ...
Mandatory. Specifies the type of message to send. Valid values are critical, error, warning, info, and debug. The module provides shorthand methods with those names to call notify.
critical
error
warning
info
debug
$roll->notify(..., "Message to send",
Mandatory. Takes a string that specifies the message to send to www.rollbar.com.
$roll->notify( ..., ..., { any => 'custom', optional => 'data', to => [qw/send goes here/], });
Optional. Takes a hashref that will be converted to JSON and sent along with the notification's message.
$roll->critical( ... ); # same as $roll->notify( 'critical', ... );
$roll->error( ... ); # same as $roll->notify( 'error', ... );
$roll->warning( ... ); # same as $roll->notify( 'warning', ... );
$roll->info( ... ); # same as $roll->notify( 'info', ... );
$roll->debug( ... ); # same as $roll->notify( 'debug', ... );
say 'Access token is ' . $roll->access_token; $roll->access_token('YOUR_post_server_item_ACCESS_TOKEN');
Getter/setter for access_token argument to ->new().
say 'Code version is ' . $roll->code_version; $roll->code_version('1.42');
Getter/setter for code_version argument to ->new().
say 'Current environment is ' . $roll->environment; $roll->environment('1.42');
Getter/setter for environment argument to ->new().
$roll->callback->(); # call current callback $roll->callback( sub { say "Foo!"; } );
Getter/setter for callback argument to ->new().
Rollbar API docs: https://rollbar.com/docs/api/items_post/
Fork this module on GitHub: https://github.com/zoffixznet/WebService-Rollbar-Notifier
To report bugs or request features, please use https://github.com/zoffixznet/WebService-Rollbar-Notifier/issues
If you can't access GitHub, you can email your request to bug-webservice-rollbar-notifier at rt.cpan.org
bug-webservice-rollbar-notifier at rt.cpan.org
You can use and distribute this module under the same terms as Perl itself. See the LICENSE file included in this distribution for complete details.
LICENSE
To install WebService::Rollbar::Notifier, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WebService::Rollbar::Notifier
CPAN shell
perl -MCPAN -e shell install WebService::Rollbar::Notifier
For more information on module installation, please visit the detailed CPAN module installation guide.