API/Contact.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« API/Comment.pm ↑ Summary API/Photo.pm »
1 package Pikeo::API::Contact;
2  
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  
6 1 ▶use base qw( Pikeo::API::Base );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 use Carp;
9 use Data::Dumper;
10  
11 sub _info_fields {qw( user_id owner_id is_contact is_friend is_family )}
12  
13 =head1 NAME
14  
15 Pikeo::API::Contact - Abstraction of a pikeo use contact
16  
17 =head1 DESCRIPTION
18  
19 Provides access to a Pikeo::API::User contact details
20  
21 You should not use this module directly. See Pikeo::API::User documentation.
22  
23 =head1 FUNCTIONS
24  
25 =head2 CONSTRUCTORS
26  
27 =head3 new( \%args )
28  
29 Returns a Pikeo::API::Contact object.
30  
31 Required args are:
32  
33 =over 4
34  
35 =item * api
36  
37 Pikeo::API object
38  
39 =item * from_xml
40  
41 XML::LibXML node containing the contact details
42  
43 =back
44  
45 =cut
46 sub new {
47 my $class = shift;
48 my $params = shift;
49  
50 my $self = $class->SUPER::new($params);
51  
52 if ( $params->{from_xml} ) {
53 $self->_init_from_xml( $params->{from_xml} );
54 return $self;
55 }
56 croak "Need an xml object";
57 }
58  
59 =head2 INSTANCE METHODS
60  
61 =head3 owner()
62  
63 Pikeo::API::User that owns the contact
64  
65 =cut
66  
67 sub owner {
68 my $self = shift;
69 return Pikeo::API::User->new({ id => $self->owner_id, api => $self->api });
70 }
71  
72 =head3 user()
73  
74 Pikeo::API::User that is the contact
75  
76 =cut
77  
78 sub user {
79 my $self = shift;
80 return Pikeo::API::User->new({ id => $self->user_id, api => $self->api });
81 }
82  
83 =head3 user_id()
84  
85 =head3 owner_id()
86  
87 =head3 is_contact()
88  
89 =head3 is_friend()
90  
91 =head3 is_family()
92  
93 =cut
94  
95 sub _init_from_xml {
96 my $self = shift;
97 my $doc = shift;
98 my $nodes = $doc->findnodes("./*");
99 for ($nodes->get_nodelist()) {
100 if ( $_->to_literal eq 'null' ) {
101 $self->{$_->nodeName} = undef;
102 }
103 elsif ( $_->to_literal eq 'true' ) {
104 $self->{$_->nodeName} = 1;
105 }
106 elsif ( $_->to_literal eq 'false' ) {
107 $self->{$_->nodeName} = 0;
108 }
109 else {
110 $self->{$_->nodeName} = $_->to_literal;
111 }
112 }
113 $self->{_init} = 1;
114 }
115  
116 1;
« API/Comment.pm ↑ Summary API/Photo.pm »