| 1 | package Toolforge::MixNMatch::Struct::Catalog; | ||
| 2 | |||
| 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 Toolforge::MixNMatch::Struct::User; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 7 | use Toolforge::MixNMatch::Struct::YearMonth; | ||
| 8 | use Toolforge::MixNMatch::Object::Catalog; | ||
| 9 | |||
| 10 | our $VERSION = 0.02; | ||
| 11 | |||
| 12 | sub obj2struct { | ||
| 13 | my $obj = shift; | ||
| 14 | |||
| 15 | my $struct_hr = { | ||
| 16 | 'type' => [{ | ||
| 17 | 'type' => $obj->type, | ||
| 18 | 'cnt' => $obj->count, | ||
| 19 | }], | ||
| 20 | 'user' => [], | ||
| 21 | 'ym' => [], | ||
| 22 | }; | ||
| 23 | foreach my $year_month (@{$obj->year_months}) { | ||
| 24 | push @{$struct_hr->{'ym'}}, | ||
| 25 | Toolforge::MixNMatch::Struct::YearMonth::obj2struct($year_month); | ||
| 26 | } | ||
| 27 | foreach my $user (@{$obj->users}) { | ||
| 28 | push @{$struct_hr->{'user'}}, | ||
| 29 | Toolforge::MixNMatch::Struct::User::obj2struct($user); | ||
| 30 | } | ||
| 31 | |||
| 32 | return $struct_hr; | ||
| 33 | } | ||
| 34 | |||
| 35 | sub struct2obj { | ||
| 36 | my $struct_hr = shift; | ||
| 37 | |||
| 38 | my $year_months = []; | ||
| 39 | foreach my $year_month_hr (@{$struct_hr->{'ym'}}) { | ||
| 40 | push @{$year_months}, Toolforge::MixNMatch::Struct::YearMonth::struct2obj($year_month_hr); | ||
| 41 | } | ||
| 42 | my $users = []; | ||
| 43 | foreach my $user_hr (@{$struct_hr->{'user'}}) { | ||
| 44 | push @{$users}, Toolforge::MixNMatch::Struct::User::struct2obj($user_hr); | ||
| 45 | } | ||
| 46 | my $obj = Toolforge::MixNMatch::Object::Catalog->new( | ||
| 47 | 'count' => $struct_hr->{'type'}->[0]->{'cnt'}, | ||
| 48 | 'type' => $struct_hr->{'type'}->[0]->{'type'}, | ||
| 49 | 'users' => $users, | ||
| 50 | 'year_months' => $year_months, | ||
| 51 | ); | ||
| 52 | |||
| 53 | return $obj; | ||
| 54 | } | ||
| 55 | |||
| 56 | 1; | ||
| 57 | |||
| 58 | __END__ | ||