1 package CPANPLUS::Module::Author;
6 use CPANPLUS::Internals::Constants;
7 use Params::Check qw[check];
8 use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext';
10 local $Params::Check::VERBOSE = 1;
16 CPANPLUS::Module::Author
20 my $author = CPANPLUS::Module::Author->new(
21 author => 'Jack Ashton',
23 _id => INTERNALS_OBJECT_ID,
30 @dists = $author->distributions;
31 @mods = $author->modules;
33 @accessors = CPANPLUS::Module::Author->accessors;
37 C<CPANPLUS::Module::Author> creates objects from the information in the
38 source files. These can then be used to query on.
40 These objects should only be created internally. For C<fake> objects,
41 there's the C<CPANPLUS::Module::Author::Fake> class.
45 An objects of this class has the following accessors:
55 The CPAN id of the author.
59 The email address of the author, which defaults to '' if not provided.
63 The C<CPANPLUS::Internals::Object> that spawned this module object.
70 author => { required => 1 }, # full name of the author
71 cpanid => { required => 1 }, # cpan id
72 email => { default => '' }, # email address of the author
73 _id => { required => 1 }, # id of the Internals object that spawned us
76 ### autogenerate accessors ###
77 for my $key ( keys %$tmpl ) {
79 *{__PACKAGE__."::$key"} = sub {
81 $self->{$key} = $_[0] if @_;
88 my $obj = CPANPLUS::Internals->_retrieve_id( $self->_id );
97 =head2 $auth = CPANPLUS::Module::Author->new( author => AUTHOR_NAME, cpanid => CPAN_ID, _id => INTERNALS_ID [, email => AUTHOR_EMAIL] )
99 This method returns a C<CPANPLUS::Module::Author> object, based on the given
102 Returns false on failure.
110 ### don't check the template for sanity
111 ### -- we know it's good and saves a lot of performance
112 local $Params::Check::SANITY_CHECK_TEMPLATE = 0;
114 my $object = check( $tmpl, \%hash ) or return;
116 return bless $object, $class;
121 =head2 @mod_objs = $auth->modules()
123 Return a list of module objects this author has released.
129 my $cb = $self->parent;
131 my $aref = $cb->_search_module_tree(
133 ### XXX, depending on backend, this is either an object
134 ### or the cpanid string. Dont know an elegant way to
135 ### solve this right now, so passing both
136 allow => [$self, $self->cpanid],
138 return @$aref if $aref;
144 =head2 @dists = $auth->distributions()
146 Returns a list of module objects representing all the distributions
147 this author has released.
155 local $Params::Check::ALLOW_UNKNOWN = 1;
156 local $Params::Check::NO_DUPLICATES = 1;
160 module => { default => '', store => \$mod },
163 my $args = check( $tmpl, \%hash ) or return;
165 ### if we didn't get a module object passed, we'll find one ourselves ###
167 my @list = $self->modules;
171 error( loc( "This author has released no modules" ) );
176 my $file = $mod->checksums( %hash );
177 my $href = $mod->_parse_checksums_file( file => $file ) or return;
180 for my $name ( keys %$href ) {
182 ### shortcut asap, so we avoid extra ops. On big checksums files
183 ### the call to clone() takes up a lot of time.
184 ### .meta files are now also in the checksums file,
185 ### which means we have to filter out things that dont
187 next if $mod->package_extension( $name ) eq META_EXT;
189 ### used to do this wiht ->clone. However, that calls ->dslip,
190 ### (which is wrong anyway, as we're doing a different module),
191 ### which in turn calls ->contains, which scans the entire
192 ### module tree using _search_module_tree, which uses P::C
193 ### and is therefor VERY VERY slow.
194 ### so let's do this the direct way for speed ups.
195 my $dist = CPANPLUS::Module::Fake->new(
196 module => do { my $m = $mod->package_name( $name );
199 version => $mod->package_version( $name ),
201 path => $mod->path, # same author after all
202 author => $mod->author, # same author after all
203 mtime => $href->{$name}->{'mtime'}, # release date
219 Returns a list of all accessor methods to the object
223 sub accessors { return keys %$tmpl };
228 # c-indentation-style: bsd
230 # indent-tabs-mode: nil
232 # vim: expandtab shiftwidth=4: