| Business-SLA documentation | Contained in the Business-SLA distribution. |
Business::SLA -
use Business::SLA;
my $SLAObj = Business::SLA->new(
BusinessHours => new Business::Hours,
InHoursDefault => '2 real hours',
OutOfHoursDefault => '1 business hour',
);
# or set/change options later
$SLAObj->SetBusinessHours( new Business::Hours );
$SLAObj->SetInHoursDefault('2 real hours');
$SLAObj->SetOutOfHoursDefault('1 business hour');
# add service levels
$SLAObj->Add( '2 real hours' => RealMinutes => 2*60 );
$SLAObj->Add( '1 business hour' => BusinessMinutes => 60 );
$SLAObj->Add( 'next business minute' );
This module is a simple tool for handling operations related to Service Level Agreements.
Creates and returns new Business::SLA object.
Takes a hash with values of BusinessHours, InHoursDefault and OutOfHoursDefault options. You can ommit these options and set them latter using methods (see below).
Sets a Business::Hours object to use for calculations. This module works without this option, but looses most functionality you can get with it.
It's possible use any object that API-compatible with Business::Hours.
Returns the current Business::Hours object or undef if it's not set.
Sets the default service level for times inside of business hours.
Takes a service level.
Returns the default service level for times inside of business hours.
Sets the default service level for times outside of business hours.
Takes a service level.
Note that BusinessHours are used for calculations, so this option makes not much sense without business hours have been set.
Returns the default service level for times outside of business hours.
Returns true if the date passed in is in business hours, and false otherwise. If no business hours have been set, returns true by default.
Takes a date in Unix time format (number of seconds since the epoch).
Returns the default servise level for the specified time.
Takes a date in Unix time format (number of seconds since the epoch).
Adds or replaces a service level definition.
Takes a service level and a hash with agreements. In the hash you can define BusinessMinutes, RealMinutes and StartImmediately boolean option.
The number of real minutes to add for the specified SLA.
Takes a service level.
The number of business minutes to add for the specified SLA.
Takes a service level.
Returns true if things should be started immediately for a service level. See also Add and Starts.
Takes the service level.
Returns the starting time, given a date and a service level.
If the service level's been defined as StartImmediately then returns the same date, as well this also happens if business hours are not set.
Takes a date in Unix time format (number of seconds since the epoch) and a service level.
Returns the due time, given an SLA and a date.
Takes a date in Unix time format (number of seconds since the epoch) and the hash key for the SLA.
Send email to bug-business-sla@rt.cpan.org
Linda Julien
Best Practical Solutions, LLC
leira@bestpractical.com
http://www.bestpractical.com
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
perl(1), Business::Hours.
| Business-SLA documentation | Contained in the Business-SLA distribution. |
package Business::SLA; use strict; use warnings; use vars qw($VERSION); $VERSION = '0.05';
sub new { my $class = shift; my $self = bless( { @_ }, ref($class) || $class ); return ($self); }
sub SetBusinessHours { my $self = shift; my $bizhours = shift; return $self->{'BusinessHours'} = $bizhours; }
sub BusinessHours { my $self = shift; return $self->{'BusinessHours'}; }
sub SetInHoursDefault { my $self = shift; my $sla = shift; return $self->{'InHoursDefault'} = $sla; }
sub InHoursDefault { my $self = shift; return $self->{'InHoursDefault'}; }
sub SetOutOfHoursDefault { my $self = shift; my $sla = shift; $self->{'OutOfHoursDefault'} = $sla; }
sub OutOfHoursDefault { my $self = shift; return $self->{'OutOfHoursDefault'}; }
sub IsInHours { my $self = shift; my $date = shift; # if no business hours are set, by definition we're in hours if ( my $bhours = $self->BusinessHours ) { return $bhours->first_after($date) == $date? 1 : 0; } return 1; }
sub SLA { my $self = shift; my $date = shift; if ( $self->IsInHours($date) ) { return $self->InHoursDefault; } else { return $self->OutOfHoursDefault; } }
sub Add { my $self = shift; my $sla = shift; return $self->{'hash'}->{$sla} = { @_ }; }
sub AddRealMinutes { my $self = shift; my $sla = shift; return 0 unless exists $self->{'hash'}{ $sla }{'RealMinutes'}; return $self->{'hash'}{ $sla }{'RealMinutes'} || 0; }
sub AddBusinessMinutes { my $self = shift; my $sla = shift; return undef unless $self->BusinessHours; return 0 unless exists $self->{'hash'}{ $sla }{'BusinessMinutes'}; return $self->{'hash'}{ $sla }{'BusinessMinutes'} || 0; }
sub StartImmediately { my $self = shift; my $sla = shift; return $self->{'hash'}{ $sla }{'StartImmediately'} || 0; }
sub Starts { my $self = shift; my $date = shift; my $sla = shift || $self->SLA( $date ); return $date if $self->StartImmediately( $sla ); if ( my $bhours = $self->BusinessHours ) { return $bhours->first_after( $date ); } else { return $date; } }
sub Due { my $self = shift; my $date = shift; my $sla = shift || $self->SLA( $date ); # find start time my $due = $self->Starts($date, $sla); # don't add business minutes unless we have some set if ( my $bminutes = $self->AddBusinessMinutes($sla) ) { $due = $self->BusinessHours->add_seconds( $due, 60 * $bminutes ); } $due += ( 60 * $self->AddRealMinutes($sla) ); return $due; }
1;