blib/lib/Games/WoW/Armory.pm

filter: Statementstmt 31.9% 67 / 210 Branchbran 21.7% 10 / 46 Conditioncond 20.0% 1 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 76.4% 13 / 17 Podpod 100% 7 / 7 totaltotal 34.0% 98 / 288 CC 34 SCAR 33.9
CC
34
Cov
30%
get_arena_teams
72.0
get_heroic_access
56.0
search_guild
30.0
CRAP 29.6
↑ Summary
1 package Games::WoW::Armory;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use base qw(Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 __PACKAGE__->mk_accessors(
12 qw(character url team guild)
13 );
14  
15 4 our $VERSION = '0.0.7_1';
16  
17 =head1 NAME
18  
19 Games::WoW::Armory - Access to the WoW Armory
20  
21  
22 =head1 SYNOPSIS
23  
24 use Games::WoW::Armory;
25  
26 my $armory = Games::WoW::Armory->new();
27 $armory->search_character( { realm => 'Elune',
28 character => 'Aarnn',
29 country => 'EU } );
30 print $armory->character->name;
31 print $armory->character->race;
32 print $armory->character->level;
33  
34 =head2 METHOD
35  
36 =head3 fetch_data
37  
38 Fetch the data, and store the result in $self->{data}
39  
40 =head3 search_character
41  
42 Search a character. Required params:
43  
44 realm | character | country
45 realm : name of the realm
46 character : name of a character
47 country : name of the country (EU|US)
48
49 List of accessor for character:
50  
51 =over 4
52  
53 =item * name: character name
54  
55 =item * guildName: guild name
56  
57 =item * arenaTeams: list of teams the character is in. Each team in the array is a Games::WoW::Armory::Team object
58  
59  
60 foreach my $team (@{$armory->character->arenaTeams}){
61 print $team->name;
62 foreach my $char (@{$team}){
63 print $char->name . " " . $char->race;
64 }
65 }
66  
67  
68 =item * battleGroup: the battlegroup name
69  
70 =item * realm: realm name
71  
72 =item * race: race name
73  
74 =item * gender: gender of the character
75  
76 =item * faction: faction the character belongs to
77  
78 =item * level: level of the character
79  
80 =item * lastModified:
81  
82 =item * title: highest rank in the old PVP mode
83  
84 =item * class: class name
85  
86 =item * rank: rank
87  
88 =item * teamRank: rank in the team
89  
90 =item * seasonGamesPlayed: number of games played in the current season
91  
92 =item * seasonGamesWon: number of games win in the current season
93  
94 =item * heroic_access: list of heroic access for the character
95  
96  
97 foreach my $key ( @{ $armory->character->heroic_access } ) {
98 print "Have access to the $key.\n";
99 }
100  
101  
102 =item * characterinfo: a hash with lot of informations about the character
103  
104 =item * skill: a hash with all the skill reputation
105  
106 =item * reputation: a hash with all the character reputation
107  
108 =back
109  
110 =head3 get_arena_teams
111  
112 Get arena teams for a player
113  
114 =head3 get_reputation
115  
116 Get reputation for a player
117  
118 =head3 search_guild
119  
120 Search for a guild. required params :
121
122 realm | guild | country
123 realm : name of the realm
124 guild : name of the guild
125 country : name of the country (EU|US)
126
127 List of accessor for guild:
128  
129 =over 4
130  
131 =item * realm: name of the realm
132  
133 =item * name: name of the guild
134  
135 =item * battleGroup: name of the battleGroup
136  
137 =item * members: array with all the member. Each member is a Games::WoW::Armory::Character object.
138  
139 =back
140  
141 foreach my $member (@{$armory->guild->members}){
142 print $member->name;
143 }
144  
145 =head3 search_team
146  
147 Search for a team. required params :
148
149 team | ts | battlegroup | country
150 battlegroup : name of the battlegroup
151 ts : type (2vs2 | 3vs3 | 5vs5) juste the number (eg: ts => 5)
152 team : name of the team
153 country : name of the country (EU|US)
154  
155 List of accessor for team:
156  
157 =over 4
158  
159 =item * seasonGamesPlayed: number of games played this season
160  
161 =item * rating:
162  
163 =item * size: number of members in the team
164  
165 =item * battleGroup: name of the battlegroup
166  
167 =item * realm: name of the realm
168  
169 =item * lastSeasonRanking: ranking in the last season
170  
171 =item * factionId: faction ID, 0 for alliance, 1 for Horde
172  
173 =item * ranking:
174  
175 =item * name: name of the team
176  
177 =item * relevance:
178  
179 =item * seasonGamesWon: number of games won
180  
181 =item * members: team members in an array, all the members are a Games::WoW::Armory::Character object
182  
183 =back
184  
185 foreach my $member (@{$armory->team->members}){
186 print $member->name;
187 }
188  
189 =head3 get_heroic_access
190  
191 Store in $self->character->heroic_access the list of keys the user can buy for the instances in heroic mode.
192  
193 =cut
194  
195 4 our $WOW_EUROPE = "http://eu.wowarmory.com/";
196 4 our $WOW_US = 'http://www.wowarmory.com/';
197  
198 4 our $HEROIC_REPUTATIONS = {
199 "Keepers of Time" => "Key of Time",
200 "Lower City" => "Auchenai Key",
201 "The Sha'tar" => "Warpforged Key",
202 "Honor Hold" => "Flamewrought Key",
203 "Thrallmar" => "Flamewrought Key",
204 "Cenarion Expedition" => "Reservoir Key",
205 };
206  
207 2 ▶sub fetch_data {
Subroutine fetch_data: called CC=5 SCAR=17.1
Pod documented
208 2 my ( $self, $params ) = @_;
209 2 ▶ $self->{ ua } = LWP::UserAgent->new() || croak $!;
Condition50%1/2
'LWP::UserAgent'->new || croak($!)
l!l
20
MC/DC0%0/1
'LWP::UserAgent'->new || croak($!)
'LWP::UserAgent'->new
Truth table50%1/2
A
A= 'LWP::UserAgent'->new
Aresult
11
00
210 $self->{ ua }->agent(
211 2 "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"
212 );
213  
214 2 my $base_url;
215 2 ▶ if ( $$params{ country } =~ /eu/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($params->{'country'} =~ /eu/i) { } 2 0 2
elsif ($params->{'country'} =~ /us/i) { } 0 0 0
216 2 $base_url = $WOW_EUROPE;
217 }
218 elsif ( $$params{ country } =~ /us/i ) {
219 0 $base_url = $WOW_US;
220 }
221 else {
222 0 croak "Unknow region code, please choose US or EU";
223 }
224  
225 2 ▶ if ( defined $$params{ team } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{'team'}) { } 1 1 2
226 $self->url( $base_url
227 . $$params{ xml } . "?r="
228 . $$params{ realm } . "&ts="
229 . $$params{ ts } . "&t="
230 1 . $$params{ team } );
231  
232 }
233 else {
234 $self->url( $base_url
235 . $$params{ xml } . "?r="
236 . $$params{ realm } . "&n="
237 1 . $$params{ name } );
238  
239 }
240  
241 2 $self->{ resultat } = $self->{ ua }->get( $self->url );
242  
243 2 $self->{ xp } = XML::Simple->new;
244 2 $self->{ data } = $self->{ xp }->XMLin( $self->{ resultat }->content );
245 }
246  
247 1 ▶sub search_character {
Subroutine search_character: called CC=4 SCAR=22.7
Pod documented
248 1 my ( $self, $params ) = @_;
249  
250 1 my $xml = 'character-sheet.xml';
251  
252 croak "you need to specify a character name"
253 1 ▶ unless defined $$params{ character };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"character"} 0 1 1
254 1 ▶ croak "you need to specify a realm" unless defined $$params{ realm };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"realm"} 0 1 1
255 croak "you need to specify a country name"
256 1 ▶ unless defined $$params{ country };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"country"} 0 1 1
257  
258 $self->fetch_data(
259 { xml => $xml,
260 realm => $$params{ realm },
261 name => $$params{ character },
262 country => $$params{ country }
263 }
264 1 );
265
266 0 my $character = $self->{ data }{ characterInfo }{ character };
267 0 my $skill = $self->{ data }{ characterInfo }{ skillTab };
268 0 my $characterinfo = $self->{ data }{ characterInfo }{ characterTab };
269
270 0 $self->character( Games::WoW::Armory::Character->new );
271 0 $self->character->name( $$character{ name } );
272 0 $self->character->class( $$character{ class } );
273 0 $self->character->guildName( $$character{ guildName } );
274  
275 0 $self->character->battleGroup( $$character{ battleGroup } );
276 0 $self->character->realm( $$character{ realm } );
277 0 $self->character->race( $$character{ race } );
278 0 $self->character->gender( $$character{ gender } );
279 0 $self->character->faction( $$character{ faction } );
280 0 $self->character->level( $$character{ level } );
281 0 $self->character->lastModified( $$character{ lastModified } );
282 0 $self->character->title( $$character{ title } );
283  
284 0 $self->character->skill( $skill );
285 0 $self->character->characterinfo( $characterinfo );
286
287 # Reputation information requires a separate XML file.
288 0 $self->get_reputation( $params );
289  
290 0 $self->get_arena_teams( $params );
291 }
292  
293 0 ▶sub get_reputation {
Subroutine get_reputation: not called CC=4 SCAR=30.0
Pod documented
294 0 my ( $self, $params ) = @_;
295  
296 0 my $xml = 'character-reputation.xml';
297  
298 croak "you need to specify a character name"
299 0 ▶ unless defined $$params{ character };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"character"} 0 0 0
300 0 ▶ croak "you need to specify a realm" unless defined $$params{ realm };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"realm"} 0 0 0
301 croak "you need to specify a country name"
302 0 ▶ unless defined $$params{ country };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"country"} 0 0 0
303  
304 $self->fetch_data(
305 { xml => $xml,
306 realm => $$params{ realm },
307 name => $$params{ character },
308 country => $$params{ country }
309 }
310 0 );
311  
312 0 my $reputation = $self->{ data }{ characterInfo }{ reputationTab };
313 0 $self->character->reputation( $reputation );
314 0 $self->get_heroic_access;
315 }
316  
317 0 ▶sub get_arena_teams {
Subroutine get_arena_teams: not called CC=8 SCAR=42.8
Pod documented
318 0 my ( $self, $params ) = @_;
319  
320 0 my $xml = 'character-arenateams.xml';
321  
322 croak "you need to specify a character name"
323 0 ▶ unless defined $$params{ character };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"character"} 0 0 0
324 0 ▶ croak "you need to specify a realm" unless defined $$params{ realm };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"realm"} 0 0 0
325 croak "you need to specify a country name"
326 0 ▶ unless defined $$params{ country };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"country"} 0 0 0
327  
328 $self->fetch_data(
329 { xml => $xml,
330 realm => $$params{ realm },
331 name => $$params{ character },
332 country => $$params{ country }
333 }
334 0 );
335  
336 my $arena_team
337 0 = $self->{data}{characterInfo}{character}{arenaTeams}{arenaTeam};
338  
339 # XML::Simple will not divide team information up into keys
340 # (based on team name) unless the character is a member of more
341 # than one team. The following logic tries to figure this out:
342 my @teams = ( exists $$arena_team{name} )
343 ? ( $arena_team )
344 0 ▶ : map +{ %{$arena_team->{$_}}, name=>$_ }, (keys %{$arena_team});
Branch: 1 branch
BranchTrueFalseTotal
exists $arena_team->{'name'} ? : 0 0 0
345  
346 0 my @team_objs;
347 0 foreach my $team ( @teams ){
348 0 my $t = Games::WoW::Armory::Team->new;
349 0 $t->name($$team{name});
350 0 $t->seasonGamesPlayed($$team{seasonGamesPlayed});
351 0 $t->size($$team{size});
352 0 $t->rating($$team{rating});
353 0 $t->battleGroup($$team{battleGroup});
354 0 $t->realm($$team{realm});
355 0 $t->lastSeasonRanking($$team{lastSeasonRanking});
356 0 $t->factionId($$team{factionId});
357 0 $t->ranking($$team{ranking});
358 0 $t->seasonGamesWon($$team{seasonGamesWon});
359 0 my @members;
360  
361 0 my $members = $$team{members}{character};
362  
363 0 ▶ if (defined $members->{name} ) { my %hash = %$members ; delete $hash{name}; $members = { $members->{name} => \%hash } };
Branch: 1 branch
BranchTrueFalseTotal
if (defined $members->{"name"}) 0 0 0
364  
365 0 foreach my $member (keys %{$members}){
366 0 my $m = Games::WoW::Armory::Character->new;
367 0 $m->name($member);
368 0 $m->race($$members{$member}{race});
369 0 $m->seasonGamesPlayed($$members{$member}{seasonGamesPlayed});
370 0 $m->teamRank($$members{$member}{teamRank});
371 0 $m->race($$members{$member}{race});
372 0 $m->gender($$members{$member}{gender});
373 0 $m->seasonGamesWon($$members{$member}{seasonGamesWon});
374 0 $m->guildName($$members{$member}{guild});
375 0 $m->class($$members{$member}{class});
376 0 push @members, $m;
377 }
378 0 $t->members(\@members);
379 0 push @team_objs, $t;
380 }
381 0 $self->character->arenaTeams( \@team_objs );
382 }
383  
384 0 ▶sub search_guild {
Subroutine search_guild: not called CC=5 SCAR=34.0
Pod documented
385 0 my ( $self, $params ) = @_;
386  
387 0 my $xml = "guild-info.xml";
388  
389 0 ▶ croak "you need to specify a guild name" unless defined $$params{ guild };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"guild"} 0 0 0
390 0 ▶ croak "you need to specify a realm" unless defined $$params{ realm };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"realm"} 0 0 0
391 croak "you need to specify a country name"
392 0 ▶ unless defined $$params{ country };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"country"} 0 0 0
393  
394 $self->fetch_data(
395 { xml => $xml,
396 realm => $$params{ realm },
397 name => $$params{ guild },
398 country => $$params{ country }
399 }
400 0 );
401  
402 0 $self->guild( Games::WoW::Armory::Guild->new );
403 0 my $guild = $self->{ data }{ guildInfo };
404 my $members
405 0 = $self->{ data }{ guildInfo }{ guild }{ members }{ character };
406  
407 0 $self->guild->name( $$guild{ guildHeader }{ name } );
408 0 $self->guild->battleGroup( $$guild{ guildHeader }{ battleGroup } );
409 0 $self->guild->realm( $$guild{ guildHeader }{ realm } );
410  
411 0 my @members;
412 0 foreach my $member ( keys %{ $members } ) {
413 0 my $m = Games::WoW::Armory::Character->new;
414 0 $m->name( $member );
415 0 $m->level( $$members{ $member }{ level } );
416 0 $m->race( $$members{ $member }{ race } );
417 0 $m->class( $$members{ $member }{ class } );
418 0 $m->rank( $$members{ $member }{ rank } );
419 0 $m->gender( $$members{ $member }{ gender } );
420 0 push @members, $m;
421 }
422 0 $self->guild->members( \@members );
423 }
424  
425 1 ▶sub search_team {
Subroutine search_team: called CC=7 SCAR=33.8
Pod documented
426 1 my ( $self, $params ) = @_;
427  
428 1 my $xml = "team-info.xml";
429 1 ▶ croak "you need to specify a team name" unless defined $$params{ team };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"team"} 0 1 1
430 croak "you need to specify a country name"
431 1 ▶ unless defined $$params{ country };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"country"} 0 1 1
432 1 ▶ croak "you need to specify a team style" unless defined $$params{ ts };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"ts"} 0 1 1
433 croak "you need to specify a realm name"
434 1 ▶ unless defined $$params{ realm };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"realm"} 0 1 1
435  
436 $self->fetch_data(
437 { xml => $xml,
438 team => $$params{ team },
439 realm => $$params{ realm },
440 ts => $$params{ ts },
441 country => $$params{ country }
442 }
443 1 );
444  
445 0 my $arena_team = $self->{ data }{ teamInfo }{ arenaTeam };
446 my $members
447 0 = $self->{ data }{ teamInfo }{ arenaTeam }{ members }{ character };
448 0 ▶ if (defined $members->{name} ) { my %hash = %$members ; delete $hash{name}; $members = { $members->{name} => \%hash } };
Branch: 1 branch
BranchTrueFalseTotal
if (defined $members->{"name"}) 0 0 0
449  
450 0 $self->team( Games::WoW::Armory::Team->new() );
451 0 $self->team->seasonGamesPlayed( $$arena_team{ seasonGamesPlayed } );
452 0 $self->team->rating( $$arena_team{ rating } );
453 0 $self->team->size( $$arena_team{ size } );
454 0 $self->team->battleGroup( $$arena_team{ battleGroup } );
455 0 $self->team->realm( $$arena_team{ realm } );
456 0 $self->team->lastSeasonRanking( $$arena_team{ lastSeasonRanking } );
457 0 $self->team->factionId( $$arena_team{ factionId } );
458 0 $self->team->ranking( $$arena_team{ ranking } );
459 0 $self->team->name( $$arena_team{ name } );
460 0 $self->team->relevance( $$arena_team{ relevance } );
461 0 $self->team->seasonGamesWon( $$arena_team{ seasonGamesWon } );
462  
463 0 my @members;
464 0 foreach my $member ( keys %{ $members } ) {
465 0 my $m = Games::WoW::Armory::Character->new;
466 0 $m->name( $member );
467 0 $m->class( $$members{ $member }{ class } );
468 0 $m->realm( $$members{ $member }{ realm } );
469 0 $m->battleGroup( $$members{ $member }{ battleGroup } );
470 0 $m->race( $$members{ $member }{ race } );
471 0 $m->gender( $$members{ $member }{ gender } );
472 0 $m->guildName( $$members{ $member }{ guild } );
473 0 push @members, $m;
474 }
475 0 $self->team->members( \@members );
476 }
477  
478 0 ▶sub get_heroic_access {
Subroutine get_heroic_access: not called CC=7 SCAR=40.3
Pod documented
479 0 my $self = shift;
480  
481 0 my @heroic_array;
482 0 foreach my $rep ( keys %{ $self->character->reputation } ) {
483 0 foreach my $fac ( keys %{ $self->character->reputation->{ $rep } } ) {
484 0 foreach my $city (
485 0 keys %{ $self->character->reputation->{ $rep }{ $fac }{ 'faction' } } )
486 {
487 0 foreach my $r ( keys %{ $HEROIC_REPUTATIONS } ) {
488 0 ▶ if ( $r eq $city
Branch: 1 branch
BranchTrueFalseTotal
if ($r eq $city and $self->character->reputation->{$rep}{$fac}{"faction"}{$city}{"reputation"} >= 21000) 0 0 0
Condition0%0/3
$r eq $city and $self->character->reputation->{$rep}{$fac}{"faction"}{$city}{"reputation"} >= 21000
!ll&&!rl&&r
000
MC/DC0%0/2
$r eq $city and $self->character->reputation->{$rep}{$fac}{"faction"}{$city}{"reputation"} >= 21000
$r eq $city $self->character->reputation->{$rep}{$fac}{"faction"}{$city}{"reputation"} >= 21000
Truth table0%0/3
A and B
A= $r eq $cityB= $self->character->reputation->{$rep}{$fac}{"faction"}{$city}{"reputation"} >= 21000
ABresult
0X0
100
111
489 && $self->character->reputation->{ $rep }{ $fac }{ 'faction' }
490 { $city }{ 'reputation' } >= 21000 )
491 {
492 0 push @heroic_array, $$HEROIC_REPUTATIONS{ $r };
493 }
494 }
495 }
496 }
497 }
498 0 $self->character->heroic_access( \@heroic_array );
499 }
500  
501 =head1 BUGS AND LIMITATIONS
502  
503 Please report any bugs or feature requests to
504 C<bug-games-wow-armory@rt.cpan.org>, or through the web interface at
505 L<http://rt.cpan.org>.
506  
507 =head1 AUTHOR
508  
509 franck cuny C<< <franck.cuny@gmail.com> >>
510 Andrew Yochum C<< <andrewyochum@gmail.com> >>
511  
512 =head1 LICENCE AND COPYRIGHT
513  
514 Copyright (c) 2007, franck cuny C<< <franck.cuny@gmail.com> >>. All rights reserved.
515  
516 This module is free software; you can redistribute it and/or
517 modify it under the same terms as Perl itself. See L<perlartistic>.
518  
519 =cut
520  
521 4 1;
522  
523 package Games::WoW::Armory::Team;
524  
525 4 ▶use base qw(Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
526  
527 4 __PACKAGE__->mk_accessors(
528 qw(seasonGamesPlayed rating size battleGroup realm lastSeasonRanking factionId ranking name relevance seasonGamesWon members)
529 );
530  
531 4 1;
532  
533 package Games::WoW::Armory::Guild;
534  
535 4 ▶use base qw(Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
536  
537 4 __PACKAGE__->mk_accessors( qw(realm name battleGroup members) );
538  
539 4 1;
540  
541 package Games::WoW::Armory::Character;
542  
543 4 ▶use base qw(Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
544  
545 4 __PACKAGE__->mk_accessors(
546 qw(name guildName arenaTeams battleGroup realm race gender faction level lastModified title class rank teamRank seasonGamesPlayed seasonGamesWon heroic_access characterinfo skill reputation)
547 );
548  
549 4 1;
550  
551 __END__
↑ Summary