| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Mojo::InfluxDB::Point; | 
| 2 |  |  |  |  |  |  | # ABSTRACT: Data point dynamic container | 
| 3 |  |  |  |  |  |  | $Mojo::InfluxDB::Point::VERSION = '0.1'; | 
| 4 | 1 |  |  | 1 |  | 10 | use Mojo::Base -base, -signatures; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 6 |  | 
| 5 | 1 |  |  | 1 |  | 1171 | use DateTime; | 
|  | 1 |  |  |  |  | 490483 |  | 
|  | 1 |  |  |  |  | 64 |  | 
| 6 | 1 |  |  | 1 |  | 828 | use DateTime::Format::Strptime; | 
|  | 1 |  |  |  |  | 56992 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | has [qw/ time_zone fields /]; | 
| 9 |  |  |  |  |  |  | has time  => sub { die "A point without time is pointless!" }; | 
| 10 |  |  |  |  |  |  | has at    => sub($self) { | 
| 11 |  |  |  |  |  |  | state $strp = DateTime::Format::Strptime->new( pattern => '%FT%T%Z' ); | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | my $dt = $strp->parse_datetime( $self->time ); | 
| 14 |  |  |  |  |  |  | $dt->set_time_zone( $self->time_zone ) if $self->time_zone; | 
| 15 |  |  |  |  |  |  | $dt; | 
| 16 |  |  |  |  |  |  | }; | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 0 |  |  | 0 | 1 |  | sub inflate($class, $src) { | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 19 | 0 |  | 0 |  |  |  | my $time = delete $src->{time} || die "A point without time is pointless!"; | 
| 20 | 0 |  |  |  |  |  | my @fields = keys %$src; | 
| 21 | 0 |  |  |  |  |  | has($_) for @fields; | 
| 22 | 0 |  |  |  |  |  | $class->new( time => $time, fields => \@fields, %$src ); | 
| 23 |  |  |  |  |  |  | } | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | 1; | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | __END__ | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | =pod | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | =encoding UTF-8 | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | =head1 NAME | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | Mojo::InfluxDB::Point - Data point dynamic container | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | =head1 VERSION | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | version 0.1 | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | You won't usually deal with this objects, but get it from L<InfluxDB::Row> or L<InfluxDB::Result> points() methods. | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | Anyway, given the dynamical nature of this object, if you need to manually contruct one, you need to use the inflate() method: | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | use Mojo::InfluxDB::Point; | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | my $point = Mojo::InfluxDB::Point->inflate({ | 
| 50 |  |  |  |  |  |  | time   => '2020-09-19T07:00:00Z', # required! | 
| 51 |  |  |  |  |  |  | tags   => [qw/ one two seven /], | 
| 52 |  |  |  |  |  |  | status => "SECONDARY" | 
| 53 |  |  |  |  |  |  | }); | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | This class is a dynamic container of data points coming from L<InfluxDB::Row>. It only requires to have a time and will dinamically create object attributes for the rest of the retrieved columns. | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | =head1 ATTRIBUTES | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | =head2 time | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | this is the string as it comes from InfluxDB and is the only required one. | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | =head2 time_zone | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | an optional time zone. See at(). | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | =head2 at | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | A L<DateTime> object representing the time() on the optionally given time_zone(). | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =head2 fields | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | Fields will be filled by inflate() at build time and will contain an array of dynamically added attributes. | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | =head1 METHODS | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | =head2 inflate | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | this is the constructor for this class. Internally it will call new(). This class method handles the "magic" of dinamically detecting fields and adding an attribute for those. | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | =head1 Methods | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | =head1 AUTHOR | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | Gonzalo Radio <gonzalo@gnzl.net> | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | This software is copyright (c) 2020 by Gonzalo Radio. | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | This is free software; you can redistribute it and/or modify it under | 
| 94 |  |  |  |  |  |  | the same terms as the Perl 5 programming language system itself. | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | =cut |