lib/JIRA/REST/Class/Factory.pm

filter: Statementstmt 81.8% 36 / 44 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 81.8% 9 / 11 Podpod 100% 4 / 4 totaltotal 74.2% 49 / 66 SCAR 11.5
CC
3
Cov
73%
make_date
12.0
factory_error
2.0
BEGIN
1.0
CRAP 3.2
« lib/JIRA/REST/Class/Issue/Comment.pm ↑ Summary lib/JIRA/REST/Class/Issue/Worklog/Item.pm »
1 package JIRA::REST::Class::Factory;
2 4 ▶use parent qw( Class::Factory::Enhanced );
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 our $VERSION = '0.10';
8 4 our $SOURCE = 'CPAN';
9 ## $SOURCE = 'GitHub'; # COMMENT
10 # the line above will be commented out by Dist::Zilla
11  
12 # ABSTRACT: A factory class for building all the other classes in L<JIRA::REST::Class|JIRA::REST::Class>.
13  
14 #pod =head1 DESCRIPTION
15 #pod
16 #pod This module imports a hash of object type package names from L<JIRA::REST::Class::FactoryTypes|JIRA::REST::Class::FactoryTypes>.
17 #pod
18 #pod =cut
19  
20 # we import the list of every class this factory knows how to make
21 #
22 4 ▶use JIRA::REST::Class::FactoryTypes qw( %TYPES );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 JIRA::REST::Class::Factory->add_factory_type( %TYPES );
24  
25 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 4 ▶use DateTime::Format::Strptime;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 #pod =internal_method B<init>
29 #pod
30 #pod Initialize the factory object. Just copies all the elements in the hashref that were passed in to the object itself.
31 #pod
32 #pod =cut
33  
34 sub init {
35 78 ▶ my $self = shift;
Subroutine init: called CC=1 SCAR=0.0
Pod documented
36 78 my $args = shift;
37 78 my @keys = keys %$args;
38 78 @{$self}{@keys} = @{$args}{@keys};
39 78 return $self;
40 }
41  
42 #pod =internal_method B<get_factory_class>
43 #pod
44 #pod Inherited method from L<Class::Factory|Class::Factory/Factory_Methods>.
45 #pod
46 #pod =internal_method B<make_object>
47 #pod
48 #pod A tweaked version of C<make_object_for_type> from
49 #pod L<Class::Factory::Enhanced|Class::Factory::Enhanced/make_object_for_type>
50 #pod that calls C<init()> with a copy of the factory.
51 #pod
52 #pod =cut
53  
54 sub make_object {
55 35 ▶ my ( $self, $object_type, @args ) = @_;
Subroutine make_object: called CC=1 SCAR=0.0
Pod documented
56 35 my $class = $self->get_factory_class( $object_type );
57 35 my $obj = $class->new( @args );
58 35 $obj->init( $self ); # make sure we pass the factory into init()
59 35 return $obj;
60 }
61  
62 #pod =internal_method B<make_date>
63 #pod
64 #pod Make it easy to get L<DateTime|DateTime> objects from the factory. Parses
65 #pod JIRA date strings, which are in a format that can be parsed by the
66 #pod L<DateTime::Format::Strptime|DateTime::Format::Strptime> pattern
67 #pod C<%FT%T.%N%z>
68 #pod
69 #pod =cut
70  
71 sub make_date {
72 0 ▶ my ( $self, $date ) = @_;
Subroutine make_date: not called CC=3 SCAR=24.8
Pod documented
73 0 ▶ return unless $date;
Branch: 1 branch
BranchTrueFalseTotal
unless $date 0 0 0
74 0 my $pattern = '%FT%T.%N%z';
75 0 state $parser = DateTime::Format::Strptime->new( pattern => $pattern );
76 return (
77 0 ▶ $parser->parse_datetime( $date )
Condition0%0/3
$parser->parse_datetime($date) || confess(qq[Unable to parse date "$date" using pattern "$pattern"])
l!l&&r!l&&!r
000
MC/DC0%0/2
$parser->parse_datetime($date) || confess(qq[Unable to parse date "$date" using pattern "$pattern"])
$parser->parse_datetime($date) confess(qq[Unable to parse date "$date" using pattern "$pattern"])
Truth table0%0/3
A || B
A= $parser->parse_datetime($date)B= confess(qq[Unable to parse date "$date" using pattern "$pattern"])
ABresult
1X1
011
000
78 or
79 confess qq{Unable to parse date "$date" using pattern "$pattern"}
80 );
81 }
82  
83 #pod =internal_method B<factory_error>
84 #pod
85 #pod Throws errors from the factory with stack traces
86 #pod
87 #pod =cut
88  
89 sub factory_error {
90 0 ▶ my ( $class, $err, @args ) = @_;
Subroutine factory_error: not called CC=1 SCAR=6.9
Pod documented
91  
92 # start the stacktrace where we called make_object()
93 0 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
94 0 Carp::confess "$err\n", @args;
95 }
96  
97 4 1;
98  
99 __END__
100  
101 =pod
102  
103 =encoding UTF-8
104  
105 =for :stopwords Packy Anderson Alexey Melezhik
106  
107 =head1 NAME
108  
109 JIRA::REST::Class::Factory - A factory class for building all the other classes in L<JIRA::REST::Class|JIRA::REST::Class>.
110  
111 =head1 VERSION
112  
113 version 0.10
114  
115 =head1 DESCRIPTION
116  
117 This module imports a hash of object type package names from L<JIRA::REST::Class::FactoryTypes|JIRA::REST::Class::FactoryTypes>.
118  
119 =head1 INTERNAL METHODS
120  
121 =head2 B<init>
122  
123 Initialize the factory object. Just copies all the elements in the hashref that were passed in to the object itself.
124  
125 =head2 B<get_factory_class>
126  
127 Inherited method from L<Class::Factory|Class::Factory/Factory_Methods>.
128  
129 =head2 B<make_object>
130  
131 A tweaked version of C<make_object_for_type> from
132 L<Class::Factory::Enhanced|Class::Factory::Enhanced/make_object_for_type>
133 that calls C<init()> with a copy of the factory.
134  
135 =head2 B<make_date>
136  
137 Make it easy to get L<DateTime|DateTime> objects from the factory. Parses
138 JIRA date strings, which are in a format that can be parsed by the
139 L<DateTime::Format::Strptime|DateTime::Format::Strptime> pattern
140 C<%FT%T.%N%z>
141  
142 =head2 B<factory_error>
143  
144 Throws errors from the factory with stack traces
145  
146 =head1 RELATED CLASSES
147  
148 =over 2
149  
150 =item * L<JIRA::REST::Class|JIRA::REST::Class>
151  
152 =item * L<JIRA::REST::Class::FactoryTypes|JIRA::REST::Class::FactoryTypes>
153  
154 =back
155  
156 =head1 AUTHOR
157  
158 Packy Anderson <packy@cpan.org>
159  
160 =head1 COPYRIGHT AND LICENSE
161  
162 This software is Copyright (c) 2017 by Packy Anderson.
163  
164 This is free software, licensed under:
165  
166 The Artistic License 2.0 (GPL Compatible)
167  
168 =cut
« lib/JIRA/REST/Class/Issue/Comment.pm ↑ Summary lib/JIRA/REST/Class/Issue/Worklog/Item.pm »