File Coverage

blib/lib/Test/Moose/More/Utils.pm
Criterion Covered Total %
statement 27 27 100.0
branch 3 4 75.0
condition 3 3 100.0
subroutine 9 9 100.0
pod 2 2 100.0
total 44 45 97.7


line stmt bran cond sub pod time code
1             #
2             # This file is part of Test-Moose-More
3             #
4             # This software is Copyright (c) 2017, 2016, 2015, 2014, 2013, 2012 by Chris Weyl.
5             #
6             # This is free software, licensed under:
7             #
8             # The GNU Lesser General Public License, Version 2.1, February 1999
9             #
10             package Test::Moose::More::Utils;
11             our $AUTHORITY = 'cpan:RSRCHBOY';
12             $Test::Moose::More::Utils::VERSION = '0.049'; # TRIAL
13             # ABSTRACT: Various utility functions for TMM (and maybe others!)
14              
15 42     42   290 use strict;
  42         121  
  42         1327  
16 42     42   251 use warnings;
  42         98  
  42         2056  
17              
18 42         559 use Sub::Exporter::Progressive -setup => {
19              
20             exports => [ qw{
21             get_mop_metaclass_for
22             known_sugar
23             } ],
24              
25             groups => { default => [':all'] },
26 42     42   271 };
  42         101  
27              
28 42     42   8035 use Carp 'croak';
  42         106  
  42         2470  
29 42     42   287 use List::Util 1.33 qw( first all );
  42         1189  
  42         2801  
30 42     42   286 use Scalar::Util 'blessed';
  42         100  
  42         9800  
31              
32              
33             sub get_mop_metaclass_for {
34 128     128 1 219466 my ($mop, $meta) = @_;
35              
36             # FIXME make this less... bad
37             # short-circuit! Better a special case here than *everywhere* else
38 128 100 100     741 return blessed $meta
39             if $mop eq 'class' || $mop eq 'role';
40              
41             # this code largely lifted from Moose::Util::MetaRole
42             my $attr =
43 110     110   18528 first { $_ }
44 110         702 map { $meta->meta->find_attribute_by_name($_) }
  220         19397  
45             ("${mop}_metaclass", "${mop}_class")
46             ;
47              
48 110 50       489 croak "Cannot find attribute storing the metaclass for $mop in " . $meta->name
49             unless $attr;
50              
51 110         440 my $read_method = $attr->get_read_method;
52              
53 110         3579 return $meta->$read_method();
54             }
55              
56              
57 16     16 1 8543 sub known_sugar () { qw{ has around augment inner before after blessed confess } }
58              
59             !!42;
60              
61             __END__
62              
63             =pod
64              
65             =encoding UTF-8
66              
67             =for :stopwords Chris Weyl Chad Etheridge Granum Karen TMM
68              
69             =head1 NAME
70              
71             Test::Moose::More::Utils - Various utility functions for TMM (and maybe others!)
72              
73             =head1 VERSION
74              
75             This document describes version 0.049 of Test::Moose::More::Utils - released July 30, 2017 as part of Test-Moose-More.
76              
77             =head1 FUNCTIONS
78              
79             =head2 get_mop_metaclass_for $mop => $meta
80              
81             Given a MOP name (e.g. attribute), rummage through $meta (a metaclass) to reveal the MOP's metaclass.
82              
83             e.g.
84              
85             get_metaclass_for attribute => __PACKAGE__->meta;
86              
87             =head2 known_sugar
88              
89             Returns a list of all the known standard Moose sugar (has, extends, etc).
90              
91             =head1 SEE ALSO
92              
93             Please see those modules/websites for more information related to this module.
94              
95             =over 4
96              
97             =item *
98              
99             L<Test::Moose::More|Test::Moose::More>
100              
101             =item *
102              
103             L<L<Moose::Util::MetaRole> -- for much of the "find the metaclass for X mop" code|L<Moose::Util::MetaRole> -- for much of the "find the metaclass for X mop" code>
104              
105             =back
106              
107             =head1 BUGS
108              
109             Please report any bugs or feature requests on the bugtracker website
110             L<https://github.com/RsrchBoy/Test-Moose-More/issues>
111              
112             When submitting a bug or request, please include a test-file or a
113             patch to an existing test-file that illustrates the bug or desired
114             feature.
115              
116             =head1 AUTHOR
117              
118             Chris Weyl <cweyl@alumni.drew.edu>
119              
120             =head1 COPYRIGHT AND LICENSE
121              
122             This software is Copyright (c) 2017, 2016, 2015, 2014, 2013, 2012 by Chris Weyl.
123              
124             This is free software, licensed under:
125              
126             The GNU Lesser General Public License, Version 2.1, February 1999
127              
128             =cut