File Coverage

blib/lib/Mason/Component/ClassMeta.pm
Criterion Covered Total %
statement 25 25 100.0
branch n/a
condition n/a
subroutine 9 9 100.0
pod n/a
total 34 34 100.0


line stmt bran cond sub pod time code
1             package Mason::Component::ClassMeta;
2             $Mason::Component::ClassMeta::VERSION = '2.23';
3 19     19   80 use File::Basename;
  19         27  
  19         1005  
4 19     19   96 use Mason::Moose;
  19         32  
  19         151  
5 19     19   37845 use Log::Any;
  19         90  
  19         203  
6              
7             my $next_id = 0;
8              
9             # Passed attributes (generated in compiled component)
10             has 'class' => ( required => 1 );
11             has 'dir_path' => ( required => 1 );
12             has 'interp' => ( required => 1, weak_ref => 1 );
13             has 'is_dhandler' => ( init_arg => undef, lazy_build => 1 );
14             has 'is_top_level' => ( required => 1 );
15             has 'object_file' => ( required => 1 );
16             has 'path' => ( required => 1 );
17             has 'source_file' => ( required => 1 );
18              
19             # Derived attributes
20             has 'id' => ( init_arg => undef, default => sub { $next_id++ } );
21             has 'log' => ( init_arg => undef, lazy_build => 1 );
22             has 'name' => ( init_arg => undef, lazy_build => 1 );
23              
24 19     19   11084 method _build_is_dhandler () {
  34     34   58  
  34         93  
25 34         54 return grep { $self->name eq $_ } @{ $self->interp->dhandler_names };
  61         1663  
  34         984  
26             }
27              
28 19     19   6907 method _build_log () {
  1     1   2  
  1         1  
29 1         27 my $log_category = "Mason::Component" . $self->path;
30 1         5 $log_category =~ s/\//::/g;
31 1         8 return Log::Any->get_logger( category => $log_category );
32             }
33              
34 19     19   6973 method _build_name () {
  34     34   67  
  34         47  
35 34         921 return basename( $self->path );
36             }
37              
38             __PACKAGE__->meta->make_immutable();
39              
40             1;
41              
42             __END__
43              
44             =pod
45              
46             =head1 NAME
47              
48             Mason::Component::ClassMeta - Meta-information about Mason component class
49              
50             =head1 SYNOPSIS
51              
52             # In a component:
53             My path is <% $.cmeta->path %>
54             My source file is <% $.cmeta->source_file %>
55              
56             =head1 DESCRIPTION
57              
58             Every L<Mason::Component|Mason::Component> class has an associated
59             L<Mason::Component::ClassMeta|Mason::Component::ClassMeta> object, containing
60             meta-information such as the component's path and source file. It can be
61             accessed with the L<cmeta|Mason::Component/cmeta> method.
62              
63             =over
64              
65             =item class
66              
67             The component class that this meta object is associated with.
68              
69             =item dir_path
70              
71             The directory of the component path, relative to the component root - e.g. for
72             a component '/foo/bar', the dir_path is '/foo'.
73              
74             =item is_top_level
75              
76             Whether the component is considered "top level", accessible directly from C<<
77             $interp->run >> or a web request. See L<Mason::Interp/top_level_extensions>.
78              
79             =item name
80              
81             The component base name, e.g. 'bar' for component '/foo/bar'.
82              
83             =item object_file
84              
85             The object file produced from compiling the component.
86              
87             =item path
88              
89             The component path, relative to the component root - e.g. '/foo/bar'.
90              
91             =item source_file
92              
93             The component source file.
94              
95             =back
96              
97             =head1 SEE ALSO
98              
99             L<Mason|Mason>
100              
101             =head1 AUTHOR
102              
103             Jonathan Swartz <swartz@pobox.com>
104              
105             =head1 COPYRIGHT AND LICENSE
106              
107             This software is copyright (c) 2012 by Jonathan Swartz.
108              
109             This is free software; you can redistribute it and/or modify it under
110             the same terms as the Perl 5 programming language system itself.
111              
112             =cut