Duration/TauStation.pm

filter: Statementstmt 92.3% 36 / 39 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 100% 6 / 6 totaltotal 91.6% 55 / 60 CC 3 SCAR 4.3
CC
3
Cov
91%
new
3.0
gct_units
2.0
BEGIN
1.0
CRAP 1.5
« Format/TauStation.pm ↑ Summary
1 package DateTime::Duration::TauStation;
2 6 $DateTime::Duration::TauStation::VERSION = '1.182290';
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use DateTime::Calendar::TauStation;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use POSIX 'floor';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use parent 'DateTime::Duration';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 DateTime::Duration::TauStation - TauStation GCT duration objects.
13  
14 =head1 SYNOPSIS
15  
16 use DateTime::Calendar::TauStation;
17 use DateTime::Format::TauStation;
18
19 my $dur = DateTime::Format::TauStation->parse_duration( 'D/20:000 GCT' );
20
21 my $dt = DateTime::Calendar::TauStation->now->add_duration( $dur );
22
23 print DateTime::Format::TauStation->format_datetime($dt);
24  
25 =head1 DESCRIPTION
26  
27 L<DateTime::Duration> subclass for GCT (Galactic Coordinated Time) datetimes
28 for the online game L<TauStation|https://taustation.space>.
29  
30 =cut
31  
32 6 my @gct_fields = qw( gct_cycle gct_day gct_segment gct_unit );
33  
34 8 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
35 8 my ( $class, %args ) = @_;
36 8 my $self;
37  
38 29 my %gct_args = map { $_ => $args{"${_}s"} }
39 8 grep { exists $args{"${_}s"} }
40 @gct_fields;
41  
42 8 ▶ if ( exists $args{gct_sign} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"gct_sign"}) 7 1 8
43 # this field isn't pluralized
44 7 $gct_args{gct_sign} = $args{gct_sign};
45 }
46  
47 8 ▶ if ( %gct_args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (%gct_args) { } 8 0 8
48 8 my $seconds = DateTime::Calendar::TauStation::gct2seconds( %gct_args );
49  
50 8 $self = $class->SUPER::new(
51 seconds => $seconds,
52 );
53 }
54 else {
55 0 croak "constructor requires at least 1 of the arguments: @gct_fields";
56 }
57  
58 8 return $self;
59 }
60  
61 =head2 gct_sign
62  
63 Returns the C<sign> portion of a duration.
64  
65 =cut
66  
67 4 ▶sub gct_sign {
Subroutine gct_sign: called CC=1 SCAR=0.0
Pod documented
68 4 my ( $self ) = @_;
69  
70 4 return DateTime::Calendar::TauStation->catastrophe->add_duration( $self )->gct_sign;
71 }
72  
73 =head1 METHODS
74  
75 =head2 gct_cycles
76  
77 Returns the C<cycle> portion of a duration.
78  
79 =cut
80  
81 4 ▶sub gct_cycles {
Subroutine gct_cycles: called CC=1 SCAR=0.0
Pod documented
82 4 my ( $self ) = @_;
83  
84 4 return DateTime::Calendar::TauStation->catastrophe->add_duration( $self )->gct_cycle;
85 }
86  
87 =head2 gct_days
88  
89 Returns the C<day> portion of a duration.
90  
91 =cut
92  
93 4 ▶sub gct_days {
Subroutine gct_days: called CC=1 SCAR=0.0
Pod documented
94 4 my ( $self ) = @_;
95  
96 4 return DateTime::Calendar::TauStation->catastrophe->add_duration( $self )->gct_day;
97 }
98  
99 =head2 gct_segments
100  
101 Returns the C<segment> portion of a duration.
102  
103 =cut
104  
105 4 ▶sub gct_segments {
Subroutine gct_segments: called CC=1 SCAR=0.0
Pod documented
106 4 my ( $self ) = @_;
107  
108 4 return DateTime::Calendar::TauStation->catastrophe->add_duration( $self )->gct_segment;
109 }
110  
111 =head2 gct_units
112  
113 Returns the C<unit> portion of a duration.
114  
115 =cut
116  
117 0 ▶sub gct_units {
Subroutine gct_units: not called CC=1 SCAR=6.9
Pod documented
118 0 my ( $self ) = @_;
119  
120 0 return DateTime::Calendar::TauStation->catastrophe->add_duration( $self )->gct_unit;
121 }
122  
123 =head1 AUTHOR
124  
125 Carl Franks
126  
127 =head1 COPYRIGHT
128  
129 Copyright (c) 2018 Carl Franks.
130  
131 This program is free software; you can redistribute it and/or modify it under
132 the same terms as Perl itself.
133  
134 The full text of the license can be found in the LICENSE file included with
135 this module.
136  
137 =head1 SEE ALSO
138  
139 L<DateTime::Calendar::TauStation>, L<DateTime::Format::TauStation>
140  
141 =cut
« Format/TauStation.pm ↑ Summary