| 1 | package Acme::2zicon; | ||||||||||
| 2 | 3 | ▶ | use 5.008001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 3 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use DateTime; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 3 | our $VERSION = "0.5"; | |||||||||
| 10 | |||||||||||
| 11 | 3 | my @members = qw( | |||||||||
| 12 | KinoshitaHiyori | ||||||||||
| 13 | MatobaKarin | ||||||||||
| 14 | NagataMinari | ||||||||||
| 15 | NakamuraAkari | ||||||||||
| 16 | NemotoNagi | ||||||||||
| 17 | NishiNanami | ||||||||||
| 18 | OkumuraNonoka | ||||||||||
| 19 | ShigematsuYuka | ||||||||||
| 20 | SuyamaEmiri | ||||||||||
| 21 | TsurumiMoe | ||||||||||
| 22 | ); | ||||||||||
| 23 | |||||||||||
| 24 | sub new { | ||||||||||
| 25 | 2 | ▶ | my $class = shift; | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 26 | 2 | my $self = bless {members => []}, $class; | |||||||||
| 27 | |||||||||||
| 28 | 2 | $self->_initialize; | |||||||||
| 29 | |||||||||||
| 30 | 2 | return $self; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | sub members { | ||||||||||
| 34 | 2 | ▶ | my ($self, $type, @members) = @_; | ||||||||
|
Subroutine
members: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||
| 35 | 2 | ▶ | @members = @{$self->{members}} unless @members; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | |||||||||||
| 37 | 2 | ▶ | return @members unless $type; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | sub sort { | ||||||||||
| 41 | 0 | ▶ | my ($self, $type, $order, @members) = @_; | ||||||||
|
Subroutine
sort: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 42 | 0 | ▶ | @members = $self->members unless @members; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | |||||||||||
| 44 | # order by desc if $order is true | ||||||||||
| 45 | 0 | ▶ | if ($order) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 0 | return sort {$b->$type <=> $a->$type} @members; | |||||||||
| 47 | } | ||||||||||
| 48 | else { | ||||||||||
| 49 | 0 | return sort {$a->$type <=> $b->$type} @members; | |||||||||
| 50 | } | ||||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | sub select { | ||||||||||
| 54 | 0 | ▶ | my ($self, $type, $number, $operator, @members) = @_; | ||||||||
|
Subroutine
select: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 55 | |||||||||||
| 56 | $self->_die('invalid operator was passed in') | ||||||||||
| 57 | 0 | ▶ | unless grep {$operator eq $_} qw(== >= <= > <); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | |||||||||||
| 59 | 0 | ▶ | @members = $self->members unless @members; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 0 | my $compare = eval "(sub { \$number $operator \$_[0] })"; | |||||||||
| 61 | |||||||||||
| 62 | 0 | return grep { $compare->($_->$type) } @members; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | sub _initialize { | ||||||||||
| 66 | 2 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_initialize: called CC=2 SCAR=6.9
| |||||||||||
| 67 | |||||||||||
| 68 | 2 | for my $member (@members) { | |||||||||
| 69 | 20 | my $module_name = 'Acme::2zicon::'.$member; | |||||||||
| 70 | |||||||||||
| 71 | 20 | eval qq|require $module_name;|; | |||||||||
| 72 | 20 | push @{$self->{members}}, $module_name->new; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 2 | return 1; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | sub _die { | ||||||||||
| 79 | 0 | ▶ | my ($self, $message) = @_; | ||||||||
|
Subroutine
_die: not called CC=1 SCAR=6.9
| |||||||||||
| 80 | 0 | Carp::croak($message); | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 3 | 1; | |||||||||
| 84 | __END__ | ||||||||||
| 85 | |||||||||||
| 86 | =encoding utf-8 | ||||||||||
| 87 | |||||||||||
| 88 | =head1 NAME | ||||||||||
| 89 | |||||||||||
| 90 | Acme::2zicon - It's new $module | ||||||||||
| 91 | |||||||||||
| 92 | =head1 SYNOPSIS | ||||||||||
| 93 | |||||||||||
| 94 | use Acme::2zicon; | ||||||||||
| 95 | |||||||||||
| 96 | my $nizicon = Acme::2zicon->new; | ||||||||||
| 97 | |||||||||||
| 98 | # retrieve the members on their activities | ||||||||||
| 99 | my @members = $nizicon->members; | ||||||||||
| 100 | |||||||||||
| 101 | # retrieve the members under some conditions | ||||||||||
| 102 | my @sorted_by_age = $nizicon->sort('age', 1); | ||||||||||
| 103 | my @selected_by_age = $nizicon->select('age', 16, '>='); | ||||||||||
| 104 | |||||||||||
| 105 | |||||||||||
| 106 | =head1 DESCRIPTION | ||||||||||
| 107 | |||||||||||
| 108 | =head1 METHODS | ||||||||||
| 109 | |||||||||||
| 110 | =head2 new | ||||||||||
| 111 | |||||||||||
| 112 | my $nizicon = Acme::2zicon->new; | ||||||||||
| 113 | |||||||||||
| 114 | Creates and returns a new Acme::2zicon object. | ||||||||||
| 115 | |||||||||||
| 116 | =head2 members | ||||||||||
| 117 | |||||||||||
| 118 | my @members = $nizicon->members(); | ||||||||||
| 119 | |||||||||||
| 120 | =head2 sort ( $type, $order \[ , @members \] ) | ||||||||||
| 121 | |||||||||||
| 122 | my @sorted_members = $nizicon->sort('age', 1); | ||||||||||
| 123 | |||||||||||
| 124 | =head2 select ( $type, $number, $operator \[, @members\] ) | ||||||||||
| 125 | |||||||||||
| 126 | # $type can be one of the same values above: | ||||||||||
| 127 | my @selected_members = $nizicon->select('age', 16, '>='); | ||||||||||
| 128 | |||||||||||
| 129 | $number $operator $member_value | ||||||||||
| 130 | |||||||||||
| 131 | |||||||||||
| 132 | =head1 LICENSE | ||||||||||
| 133 | |||||||||||
| 134 | MIT License | ||||||||||
| 135 | |||||||||||
| 136 | =head1 AUTHOR | ||||||||||
| 137 | |||||||||||
| 138 | catatsuy E<lt>catatsuy@catatsuy.orgE<gt> | ||||||||||
| 139 | |||||||||||
| 140 | =head1 SEE ALSO | ||||||||||
| 141 | |||||||||||
| 142 | (Japanese text only) | ||||||||||
| 143 | |||||||||||
| 144 | =over 4 | ||||||||||
| 145 | |||||||||||
| 146 | =item * 虹のコンキスタドール | ||||||||||
| 147 | |||||||||||
| 148 | L<http://pixiv-pro.com/2zicon/> | ||||||||||
| 149 | |||||||||||
| 150 | =item * プロフィール - 虹のコンキスタドール | ||||||||||
| 151 | |||||||||||
| 152 | L<http://pixiv-pro.com/2zicon/profile> | ||||||||||
| 153 | |||||||||||
| 154 | =back | ||||||||||
| 155 | |||||||||||
| 156 | =head1 NOTE | ||||||||||
| 157 | |||||||||||
| 158 | This product has nothing to do with pixiv Inc. and pixiv production Inc. and 2zicon. | ||||||||||
| 159 | |||||||||||
| 160 | |||||||||||
| 161 | =cut | ||||||||||
| 162 | |||||||||||