« blib/lib/SignalWire/Agents/Skills/Builtin/GoogleMaps.pm
↑ Summary
blib/lib/SignalWire/Agents/Prefabs/InfoGatherer.pm »
| 1 | package SignalWire::Agents::Skills::Builtin::Datetime; | ||||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 4 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 4 | ▶ | use POSIX qw(strftime); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 4 | extends 'SignalWire::Agents::Skills::SkillBase'; | |||||||||||
| 7 | |||||||||||||
| 8 | 4 | ▶ | use SignalWire::Agents::Skills::SkillRegistry; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 4 | SignalWire::Agents::Skills::SkillRegistry->register_skill('datetime', __PACKAGE__); | |||||||||||
| 10 | |||||||||||||
| 11 | 18 | ▶ | has '+skill_name' => (default => sub { 'datetime' }); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 18 | ▶ | has '+skill_description' => (default => sub { 'Get current date, time, and timezone information' }); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 18 | ▶ | has '+supports_multiple_instances' => (default => sub { 0 }); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | |||||||||||||
| 15 | 10 | ▶ | sub setup { 1 } | ||||||||||
|
Subroutine
setup: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 16 | |||||||||||||
| 17 | 9 | ▶ | sub register_tools { | ||||||||||
|
Subroutine
register_tools: called CC=1 SCAR=1.0
Pod
undocumented
| |||||||||||||
| 18 | 9 | my ($self) = @_; | |||||||||||
| 19 | |||||||||||||
| 20 | $self->define_tool( | ||||||||||||
| 21 | name => 'get_current_time', | ||||||||||||
| 22 | description => 'Get the current time, optionally in a specific timezone', | ||||||||||||
| 23 | parameters => { | ||||||||||||
| 24 | type => 'object', | ||||||||||||
| 25 | properties => { | ||||||||||||
| 26 | timezone => { type => 'string', description => 'Timezone (e.g. UTC, US/Eastern)', default => 'UTC' }, | ||||||||||||
| 27 | }, | ||||||||||||
| 28 | }, | ||||||||||||
| 29 | 1 | ▶ | handler => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||
| 30 | 1 | my ($args, $raw) = @_; | |||||||||||
| 31 | 1 | ▶ | my $tz = $args->{timezone} // 'UTC'; | ||||||||||
|
Condition50%1/2
$args->{"timezone"} // "UTC"
MC/DC0%0/1
$args->{"timezone"} // "UTC"
$args->{"timezone"}
Truth table50%1/2
A
A= $args->{"timezone"}
| |||||||||||||
| 32 | 1 | local $ENV{TZ} = $tz; | |||||||||||
| 33 | 1 | POSIX::tzset(); | |||||||||||
| 34 | 1 | my $time = strftime('%H:%M:%S %Z', localtime); | |||||||||||
| 35 | 1 | POSIX::tzset(); # Reset | |||||||||||
| 36 | 1 | require SignalWire::Agents::SWAIG::FunctionResult; | |||||||||||
| 37 | 1 | return SignalWire::Agents::SWAIG::FunctionResult->new( | |||||||||||
| 38 | response => "The current time in $tz is $time" | ||||||||||||
| 39 | ); | ||||||||||||
| 40 | }, | ||||||||||||
| 41 | 9 | ); | |||||||||||
| 42 | |||||||||||||
| 43 | $self->define_tool( | ||||||||||||
| 44 | name => 'get_current_date', | ||||||||||||
| 45 | description => 'Get the current date', | ||||||||||||
| 46 | parameters => { | ||||||||||||
| 47 | type => 'object', | ||||||||||||
| 48 | properties => { | ||||||||||||
| 49 | timezone => { type => 'string', description => 'Timezone (e.g. UTC, US/Eastern)', default => 'UTC' }, | ||||||||||||
| 50 | }, | ||||||||||||
| 51 | }, | ||||||||||||
| 52 | 0 | ▶ | handler => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 53 | 0 | my ($args, $raw) = @_; | |||||||||||
| 54 | 0 | ▶ | my $tz = $args->{timezone} // 'UTC'; | ||||||||||
|
Condition0%0/2
$args->{"timezone"} // "UTC"
MC/DC0%0/1
$args->{"timezone"} // "UTC"
$args->{"timezone"}
Truth table0%0/2
A
A= $args->{"timezone"}
| |||||||||||||
| 55 | 0 | local $ENV{TZ} = $tz; | |||||||||||
| 56 | 0 | POSIX::tzset(); | |||||||||||
| 57 | 0 | my $date = strftime('%Y-%m-%d', localtime); | |||||||||||
| 58 | 0 | POSIX::tzset(); | |||||||||||
| 59 | 0 | require SignalWire::Agents::SWAIG::FunctionResult; | |||||||||||
| 60 | 0 | return SignalWire::Agents::SWAIG::FunctionResult->new( | |||||||||||
| 61 | response => "The current date in $tz is $date" | ||||||||||||
| 62 | ); | ||||||||||||
| 63 | }, | ||||||||||||
| 64 | 9 | ); | |||||||||||
| 65 | } | ||||||||||||
| 66 | |||||||||||||
| 67 | 7 | ▶ | sub _get_prompt_sections { | ||||||||||
|
Subroutine
_get_prompt_sections: called CC=1 SCAR=0.0
| |||||||||||||
| 68 | return [{ | ||||||||||||
| 69 | 7 | title => 'Date and Time Information', | |||||||||||
| 70 | body => 'You can get the current date and time in any timezone.', | ||||||||||||
| 71 | bullets => [ | ||||||||||||
| 72 | 'Use get_current_time to get the current time', | ||||||||||||
| 73 | 'Use get_current_date to get the current date', | ||||||||||||
| 74 | ], | ||||||||||||
| 75 | }]; | ||||||||||||
| 76 | } | ||||||||||||
| 77 | |||||||||||||
| 78 | 2 | ▶ | sub get_parameter_schema { | ||||||||||
|
Subroutine
get_parameter_schema: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 79 | return { | ||||||||||||
| 80 | 2 | %{ SignalWire::Agents::Skills::SkillBase->get_parameter_schema }, | |||||||||||
| 81 | }; | ||||||||||||
| 82 | } | ||||||||||||
| 83 | |||||||||||||
| 84 | 4 | 1; | |||||||||||