File Coverage

blib/lib/Personality/Type/MBTI.pm
Criterion Covered Total %
statement 37 43 86.0
branch 14 22 63.6
condition 27 38 71.0
subroutine 7 9 77.7
pod 4 4 100.0
total 89 116 76.7


line stmt bran cond sub pod time code
1             package Personality::Type::MBTI;
2              
3 3     3   67333 use warnings;
  3         8  
  3         91  
4 3     3   17 use strict;
  3         6  
  3         2564  
5              
6             =head1 NAME
7              
8             Personality::Type::MBTI - Myers-Briggs Type Indicator (MBTI)
9              
10             =head1 VERSION
11              
12             Version 0.05
13              
14             =cut
15              
16             our $VERSION = '0.05';
17              
18             =head1 SYNOPSIS
19              
20             The Myers-Briggs Type Indicator (MBTI) is a personality test designed
21             to assist a person in identifying some significant personal
22             preferences.
23              
24             The Indicator is frequently used in the areas of pedagogy, group
25             dynamics, employee training, leadership training, marriage counseling,
26             and personal development.
27              
28             The types the MBTI sorts for, known as dichotomies, are extraversion
29             / introversion, sensing / intuition, thinking / feeling and judging
30             / perceiving. Each of the sixteen types is referred to by a four-letter
31             abbreviation, such as ESTJ or INFP, indicating that type's preference
32             in each dichotomy.
33              
34             The MBTI includes 93 forced-choice questions, which means there are
35             only two options. Participants may skip questions if they feel they
36             are unable to choose. Using psychometric techniques, such as item
37             response theory, the MBTI will then be scored and will attempt to
38             identify which dichotomy the participant prefers. After taking the
39             MBTI, participants are given a readout of their score, which will
40             include a bar graph and number of how many points they received on
41             a certain scale.
42              
43             This module calculates the MBTI scores on each scale and, eventually,
44             will provide integration with other personality type theories (e.g.
45             Keirsey, Big5).
46              
47             use Personality::Type::MBTI;
48              
49             my $mbti = Personality::Type::MBTI->new();
50              
51             # sample results from a questionnaire
52             my @test = qw/i e i e i n s n s n t f t f t p j p j p/;
53              
54             # calculate type
55             my $type = $mbti->type( @test );
56              
57             print "Your type is '$type'\n";
58              
59             =head1 FUNCTIONS
60              
61             =head2 new
62              
63             Creates a new Personality::Type::MBTI object.
64              
65             =cut
66              
67             sub new {
68 2     2 1 27 my $self = shift;
69 2         11 bless {@_}, $self;
70             }
71              
72             =head2 type
73              
74             Receives an array containing the results of a questinnaire (letters
75             [eisnftpj]).
76              
77             Returns:
78              
79             =over 4
80              
81             =item * scalar context
82              
83             In scalar context, it returns the lower-case mbti type (e.g. "intp").
84              
85             If any dimension cannot be correctly identified (e.g., same score for
86             "extroversion" and "introversion") it will be marked with an "x" (e.g.
87             "xntp")
88              
89             =item * list context
90              
91             In list context, it returns a hash containing the count for each
92             dimension.
93              
94             =back
95              
96             =cut
97              
98             sub type {
99 69     69 1 36747 my ( $self, @letters ) = @_;
100              
101 69         122 my %count = map( { $_ => 0 } qw/e i s n f t p j/ );
  552         1065  
102              
103 69         164 foreach (@letters) {
104 1108         1524 $_ = lc($_);
105              
106 1108 50       4877 if ( my ($weight, $letter) = /^([+-]?\d*)\s*(\w)$/ ) {
107 1108   100     3366 $weight ||= 1;
108 1108         2370 $count{$letter} += $weight;
109             }
110             }
111              
112 69         172 my $result =
113             _preference( e => $count{e}, i => $count{i} )
114             . _preference( s => $count{s}, n => $count{n} )
115             . _preference( f => $count{f}, t => $count{t} )
116             . _preference( p => $count{p}, j => $count{j} );
117              
118 69 50       386 return wantarray ? %count : $result;
119             }
120              
121             sub _preference {
122 276     276   586 my %count = @_;
123              
124 276         457 my ( $a, $b ) = keys %count;
125              
126             return
127 276 100       1223 $count{$a} > $count{$b} ? $a
    100          
128             : $count{$b} > $count{$a} ? $b
129             : 'x';
130             }
131              
132             =head2 dominant
133              
134             Receives a personality type (e.g. "infp") and returns its dominant
135             function (in this case, "fi" - introverted feeling).
136              
137             =cut
138              
139             sub dominant {
140 16     16 1 66 my ( $self, $type ) = @_;
141 16         50 my ( $ei, $ns, $ft, $jp ) = split(//, $type);
142              
143 16         27 my $orient = $ei; # always
144              
145 16         18 my $function;
146 16 100 100     163 if ( $jp eq 'p' and $ei eq 'i' or $jp eq 'j' and $ei eq 'e' ) {
    50 100        
      66        
      66        
      33        
      66        
147 8         13 $function = $ft;
148             } elsif ( $jp eq 'p' and $ei eq 'e' or $jp eq 'j' and $ei eq 'i') {
149 8         13 $function = $ns;
150             }
151              
152 16         53 return "$function$orient";
153             }
154              
155             =head2 auxiliary
156              
157             Receives a personality type (e.g. "infp") and returns its auxiliary
158             function (in this case, "ne" - extroverted intuition).
159              
160             =cut
161              
162             sub auxiliary {
163 16     16 1 61 my ( $self, $type ) = @_;
164 16         51 my ( $ei, $ns, $ft, $jp ) = split(//, $type);
165              
166 16 100       40 my $orient = $ei eq 'i' ? 'e' : 'i'; # the opposite, always
167              
168 16         19 my $function;
169 16 100 100     156 if ( $jp eq 'p' and $ei eq 'i' or $jp eq 'p' and $ei eq 'e' ) {
    50 66        
      66        
      66        
      33        
      66        
170 8         17 $function = $ft;
171             } elsif ( $jp eq 'j' and $ei eq 'e' or $jp eq 'j' and $ei eq 'i') {
172 8         14 $function = $ns;
173             }
174              
175 16         53 return "$function$orient";
176             }
177              
178             sub _keirsey {
179 0     0     my ( $self, $type ) = @_;
180              
181 0           my %keirsey = (
182             esfj => 'provider',
183             enfj => 'teacher',
184             isfp => 'composer',
185             infp => 'healer',
186             enfp => 'champion',
187             entp => 'inventor',
188             infj => 'counselor',
189             intj => 'mastermind',
190             esfp => 'performer',
191             estp => 'promoter',
192             isfj => 'protector',
193             istj => 'inspector',
194             estj => 'supervisor',
195             entj => 'field marshal',
196             istp => 'crafter',
197             intp => 'architect',
198             );
199              
200 0 0         return wantarray ? %keirsey : $keirsey{$type};
201             }
202              
203             sub _function {
204 0     0     my ( $self, $function ) = @_;
205              
206 0           my %function = (
207             'e' => 'Extraversion',
208             'i' => 'Introversion',
209             's' => 'Sensing',
210             'n' => 'iNtuition',
211             'f' => 'Feeling',
212             't' => 'Thinking',
213             'p' => 'Perceiving',
214             'j' => 'Judging',
215             );
216              
217 0 0         return wantarray ? %function : $function{$function};
218             }
219              
220             =head1 AUTHOR
221              
222             Nelson Ferraz, C<< >>
223              
224             =head1 BUGS
225              
226             Please report any bugs or feature requests to
227             C, or through the web
228             interface at
229             L.
230             I will be notified, and then you'll automatically be notified of
231             progress on your bug as I make changes.
232              
233             =head1 SUPPORT
234              
235             You can find documentation for this module with the perldoc command.
236              
237             perldoc Personality::Type::MBTI
238              
239             You can also look for information at:
240              
241             =over 4
242              
243             =item * AnnoCPAN: Annotated CPAN documentation
244              
245             L
246              
247             =item * CPAN Ratings
248              
249             L
250              
251             =item * RT: CPAN's request tracker
252              
253             L
254              
255             =item * Search CPAN
256              
257             L
258              
259             =back
260              
261             =head1 SEE ALSO
262              
263             =over 4
264              
265             =item * Myers-Briggs Type Indicator on Wikipedia
266              
267             L
268              
269             =back
270              
271             =head1 COPYRIGHT & LICENSE
272              
273             Copyright 2007 Nelson Ferraz, all rights reserved.
274              
275             This program is free software; you can redistribute it and/or modify it
276             under the same terms as Perl itself.
277              
278             =cut
279              
280             1; # End of Personality::Type::MBTI