File: ClassMeta.pm

package info (click to toggle)
libmason-perl 2.24-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 748 kB
  • sloc: perl: 4,882; makefile: 7
file content (112 lines) | stat: -rw-r--r-- 2,690 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package Mason::Component::ClassMeta;
$Mason::Component::ClassMeta::VERSION = '2.24';
use File::Basename;
use Mason::Moose;
use Log::Any;

my $next_id = 0;

# Passed attributes (generated in compiled component)
has 'class'        => ( required => 1 );
has 'dir_path'     => ( required => 1 );
has 'interp'       => ( required => 1, weak_ref => 1 );
has 'is_dhandler'  => ( init_arg => undef, lazy_build => 1 );
has 'is_top_level' => ( required => 1 );
has 'object_file'  => ( required => 1 );
has 'path'         => ( required => 1 );
has 'source_file'  => ( required => 1 );

# Derived attributes
has 'id'   => ( init_arg => undef, default => sub { $next_id++ } );
has 'log'  => ( init_arg => undef, lazy_build => 1 );
has 'name' => ( init_arg => undef, lazy_build => 1 );

method _build_is_dhandler () {
    return grep { $self->name eq $_ } @{ $self->interp->dhandler_names };
}

method _build_log () {
    my $log_category = "Mason::Component" . $self->path;
    $log_category =~ s/\//::/g;
    return Log::Any->get_logger( category => $log_category );
}

method _build_name () {
    return basename( $self->path );
}

__PACKAGE__->meta->make_immutable();

1;

__END__

=pod

=head1 NAME

Mason::Component::ClassMeta - Meta-information about Mason component class

=head1 SYNOPSIS

    # In a component:
    My path is <% $.cmeta->path %>
    My source file is <% $.cmeta->source_file %>

=head1 DESCRIPTION

Every L<Mason::Component|Mason::Component> class has an associated
L<Mason::Component::ClassMeta|Mason::Component::ClassMeta> object, containing
meta-information such as the component's path and source file. It can be
accessed with the L<cmeta|Mason::Component/cmeta> method.

=over

=item class

The component class that this meta object is associated with.

=item dir_path

The directory of the component path, relative to the component root - e.g. for
a component '/foo/bar', the dir_path is '/foo'.

=item is_top_level

Whether the component is considered "top level", accessible directly from C<<
$interp->run >> or a web request. See L<Mason::Interp/top_level_extensions>.

=item name

The component base name, e.g. 'bar' for component '/foo/bar'.

=item object_file

The object file produced from compiling the component.

=item path

The component path, relative to the component root - e.g. '/foo/bar'.

=item source_file

The component source file.

=back

=head1 SEE ALSO

L<Mason|Mason>

=head1 AUTHOR

Jonathan Swartz <swartz@pobox.com>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Jonathan Swartz.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut