blib/lib/WWW/FBX/Role/Auth.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 51 CC 4 SCAR 25.1
CC
4
Cov
0%
BUILD
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 12.3
1 package WWW::FBX::Role::Auth;
2 use 5.008001;
3 use Moose::Role;
4 use Digest::HMAC_SHA1 qw/ hmac_sha1_hex /;
5  
6 has [ qw/app_token track_id/ ] => ( isa => 'Str', is => 'rw', default => '');
7  
8 sub BUILD {
9 my $self=shift;
10 my $au_sts;
11 my $challenge;
12  
13 #Get API version if we're called first
14 $self->api_version;
15
16 unless ( $self->app_token and $self->track_id ) {
17 #Request token
18 $self->req_auth ( { app_id => $self->app_id,
19 app_name => $self->app_name,
20 app_version => $self->app_version,
21 device_name => $self->device_name } );
22 $self->track_id( $self->uar->{result}{track_id} );
23 $self->app_token( $self->uar->{result}{app_token} );
24 }
25  
26 #Check auth status or wait for physical granting on the device
27 $self->auth_progress( { suff => $self->track_id } );
28 while( ( $au_sts = $self->uar->{result}{status} ) eq "pending" ) {
29 $challenge = $self->uar->{result}{challenge};
30 print "Please Confirm on the FB - Merci d'autoriser sur la FB\n";
31 $self->auth_progress( { suff => $self->track_id } );
32 sleep 1;
33 }
34  
35 die "Authorization not granted($au_sts)" unless $au_sts eq "granted";
36  
37 unless ($challenge) {
38 $self->login;
39 $challenge = $self->uar->{result}{challenge};
40 }
41  
42 $self->open_session( {
43 app_id => $self->app_id,
44 app_version => $self->app_version,
45 password => hmac_sha1_hex( $challenge, $self->app_token ),
46 } );
47
48 $self->ua->default_header('X-Fbx-App-Auth' => $self->uar->{result}{session_token});
49  
50 }
51  
52 1;
53 __END__
54  
55 =encoding utf-8
56  
57 =head1 NAME
58  
59 WWW::FBX::Role::Auth - Provides authentication mechanism.
60  
61 =head1 SYNOPSIS
62  
63 use WWW::FBX::Role::Auth;
64  
65 =head1 DESCRIPTION
66  
67 WWW::FBX::Role::Auth is FBX Authenticator role.
68  
69 =head1 LICENSE
70  
71 Copyright (C) Laurent Kislaire.
72  
73 This library is free software; you can redistribute it and/or modify
74 it under the same terms as Perl itself.
75  
76 =head1 AUTHOR
77  
78 Laurent Kislaire E<lt>teebeenator@gmail.comE<gt>
79  
80 =cut
81