| 1 | package BusyBird::Input::Generator; | ||||||||||
| 2 | 1 | ▶ | use v5.8.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use DateTime; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use BusyBird::DateTime::Format; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Data::UUID; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 2 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 10 | 2 | my ($class, %args) = @_; | |||||||||
| 11 | my $self = bless { | ||||||||||
| 12 | 2 | ▶ | screen_name => defined($args{screen_name}) ? $args{screen_name} : "", | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | id_gen => Data::UUID->new, | ||||||||||
| 14 | }, $class; | ||||||||||
| 15 | 2 | return $self; | |||||||||
| 16 | } | ||||||||||
| 17 | |||||||||||
| 18 | 23 | ▶ | sub generate { | ||||||||
|
Subroutine
generate: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||
| 19 | 23 | my ($self, %args) = @_; | |||||||||
| 20 | 23 | ▶ | my $text = defined($args{text}) ? $args{text} : ""; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 23 | ▶ | my $level = defined($args{level}) ? $args{level} : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 23 | my $cur_time = DateTime->now; | |||||||||
| 23 | my $status = +{ | ||||||||||
| 24 | id => $self->_generate_id(), | ||||||||||
| 25 | text => $text, | ||||||||||
| 26 | created_at => BusyBird::DateTime::Format->format_datetime($cur_time), | ||||||||||
| 27 | user => { | ||||||||||
| 28 | screen_name => $self->{screen_name}, | ||||||||||
| 29 | }, | ||||||||||
| 30 | 23 | busybird => { | |||||||||
| 31 | status_permalink => "" | ||||||||||
| 32 | } | ||||||||||
| 33 | }; | ||||||||||
| 34 | 23 | ▶ | if(defined $level) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 23 | $status->{busybird}{level} = $level + 0; | |||||||||
| 36 | } | ||||||||||
| 37 | 23 | return $status; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 23 | ▶ | sub _generate_id { | ||||||||
|
Subroutine
_generate_id: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 23 | my ($self) = @_; | |||||||||
| 42 | 23 | my $namespace = $self->{screen_name}; | |||||||||
| 43 | 23 | my $uuid = $self->{id_gen}->create_str; | |||||||||
| 44 | 23 | return qq{busybird://$namespace/$uuid}; | |||||||||
| 45 | ## $cur_time = DateTime->now if not defined($cur_time); | ||||||||||
| 46 | ## my $cur_epoch = $cur_time->epoch; | ||||||||||
| 47 | ## if($self->{last_epoch} != $cur_epoch) { | ||||||||||
| 48 | ## $self->{next_sequence_number} = 0; | ||||||||||
| 49 | ## } | ||||||||||
| 50 | ## my $id = qq{busybird://$namespace/$cur_epoch/$self->{next_sequence_number}}; | ||||||||||
| 51 | ## $self->{next_sequence_number}++; | ||||||||||
| 52 | ## $self->{last_epoch} = $cur_epoch; | ||||||||||
| 53 | ## return $id; | ||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 1 | 1; | |||||||||
| 57 | __END__ | ||||||||||