File Coverage

blib/lib/Class/Scaffold/Factory/Type.pm
Criterion Covered Total %
statement 26 35 74.2
branch 2 4 50.0
condition 3 6 50.0
subroutine 9 11 81.8
pod 3 3 100.0
total 43 59 72.8


line stmt bran cond sub pod time code
1 2     2   112 use 5.008;
  2         9  
  2         86  
2 2     2   12 use warnings;
  2         5  
  2         107  
3 2     2   11 use strict;
  2         4  
  2         114  
4              
5             package Class::Scaffold::Factory::Type;
6             BEGIN {
7 2     2   36 $Class::Scaffold::Factory::Type::VERSION = '1.102280';
8             }
9             # ABSTRACT: Factory for framework object types
10 2     2   11 use parent 'Class::Factory::Enhanced';
  2         4  
  2         23  
11              
12             sub import {
13 4     4   7 shift; # We don't need the package name
14 4         9 my $spec = shift;
15 4 50 33     102 return unless defined $spec && $spec eq ':all';
16 0         0 my $pkg = caller;
17 0         0 for my $symbol (Class::Scaffold::Factory::Type->get_registered_types) {
18 0         0 my $factory_class =
19             Class::Scaffold::Factory::Type->get_registered_class($symbol);
20 2     2   9684 no strict 'refs';
  2         6  
  2         477  
21 0         0 my $target = "${pkg}::obj_${symbol}";
22 0     0   0 *$target = sub () { $factory_class };
  0         0  
23             }
24             }
25              
26             # override this method with a caching version; it's called very often
27             sub make_object_for_type {
28 3     3 1 10 my ($self, $object_type, @args) = @_;
29 3         6 our %cache;
30 3   66     54 my $class = $cache{$object_type} ||= $self->get_factory_class($object_type);
31 2         102 $class->new(@args);
32             }
33              
34             # no warnings
35 0     0 1 0 sub factory_log { }
36              
37             sub register_factory_type {
38 2     2 1 12 my ($item, @args) = @_;
39 2         29 $item->SUPER::register_factory_type(@args);
40 2 50       231 return unless $::PTAGS;
41 0           while (my ($factory_type, $package) = splice @args, 0, 2) {
42 0           $::PTAGS->add_tag("csft--$factory_type", "filename_for:$package", 1);
43             }
44             }
45             1;
46              
47              
48             __END__