From: Chris W. <la...@us...> - 2005-02-08 01:10:57
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19431/lib/OpenInteract2 Modified Files: Package.pm Log Message: add name_as_class() (small) and copy_contents_to() (larger) Index: Package.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Package.pm,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** Package.pm 2 Feb 2005 15:47:21 -0000 1.46 --- Package.pm 8 Feb 2005 01:10:41 -0000 1.47 *************** *** 11,15 **** use File::Basename qw( basename dirname ); use File::Copy qw( cp ); ! use File::Path (); use File::Spec::Functions qw( :ALL ); use File::Temp qw( tempdir ); --- 11,15 ---- use File::Basename qw( basename dirname ); use File::Copy qw( cp ); ! use File::Path qw( mkpath ); use File::Spec::Functions qw( :ALL ); use File::Temp qw( tempdir ); *************** *** 167,170 **** --- 167,178 ---- } + sub name_as_class { + my ( $self, $name ) = @_; + $name ||= $self->name; + my $class_name = ucfirst $name; + $class_name =~ s/_(\w)/\U$1\U/g; + return $class_name; + } + # don't use split here since the package name might have a '-' in it # (shouldn't happen, but still) *************** *** 433,436 **** --- 441,471 ---- + ######################################## + # COPY PACKAGE FILES + + sub copy_contents_to { + my ( $self, $dest_dir ) = @_; + my $src_dir = $self->directory; + my @copied = (); + my @same = (); + foreach my $file ( @{ $self->get_files } ) { + my $src_path = catfile( $src_dir, $file ); + my $dest_path = catfile( $dest_dir, $file ); + if ( OpenInteract2::Util->is_same_file( $src_path, $dest_path ) ) { + push @same, $file; + } + else { + $self->_create_full_path( $dest_path ); + cp( $src_path, $dest_path ) + || oi_error "Cannot copy '$src_path' -> '$dest_path': $!"; + push @copied, $file; + } + } + return { + copied => \@copied, + same => \@same, + }; + } + ######################################## *************** *** 574,578 **** # operation fails -- you don't need '|| die $!' ! File::Path::mkpath( $dirname, undef, 0755 ); return 1; --- 609,613 ---- # operation fails -- you don't need '|| die $!' ! mkpath( $dirname, undef, 0755 ); return 1; *************** *** 842,850 **** require OpenInteract2::Brick; my $brick = OpenInteract2::Brick->new( 'package' ); ! my $class_name = ucfirst $name; ! $class_name =~ s/_(\w)/\U$1\U/g; return $brick->copy_all_resources_to( $dest_dir, { package_name => $name, ! class_name => $class_name }); } --- 877,884 ---- require OpenInteract2::Brick; my $brick = OpenInteract2::Brick->new( 'package' ); ! my $class_name = $class->name_as_class( $name ); return $brick->copy_all_resources_to( $dest_dir, { package_name => $name, ! class_name => $class_name, }); } *************** *** 1499,1502 **** --- 1533,1549 ---- # Name: foo-1.52 + B<name_as_class()> + + Displays the package name as suitable for a class: leading uppercase + with camel-case internally replacing all underscores. For instance: + + $package->name( 'foo' ); + print "Class name: ", $package->name_as_class; + # Class name: Foo + + $package->name( 'music_listener' ); + print "Class name: ", $package->name_as_class; + # Class name: MusicListener + B<get_files( [ $force_read ] )> *************** *** 1522,1525 **** --- 1569,1591 ---- Returns: the full path to the distribution file created. + See also: L<OpenInteract2::Manage::Package::CreateCPAN> for creating a + CPAN distribution from your package. + + B<copy_contents_to( $destination_dir )> + + Copies all files from this package (those identified in 'MANIFEST') to + C<$destination_dir>. If C<$destination_dir> does not exist we create + it; if it does exist we overwrite any different files that match the + paths from the source package. ('Different' means the files must be of + a different size and have a different MD5 digest.) + + You typically want to use this for copying a package installed to a + website to another package -- for syncing up a directory it would + probably be faster to just use L<Archive::Zip>. + + Returns: hashref with two keys, 'copied' and 'same', each pointing to + an arrayref of relative files appropriate to the key. ('Relative' + means the path from MANIFEST, e.g. 'OpenInteract2/Action/MyAction.pm'). + B<check( \%params )> |