Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
799 lines (532 sloc) 18 KB
00:00:00.77,00:00:02.04
Hi, and welcome back to the channel.
00:00:02.23,00:00:03.90
And this time I'm going to show you a little
00:00:03.90,00:00:06.38
contribution, how you can contribute a little
00:00:06.83,00:00:08.57
code to CPAN module.
00:00:09.26,00:00:12.45
So the other day I was trying to install MIME::Lite.
00:00:12.89,00:00:14.51
And this is the way I would install it.
00:00:14.51,00:00:16.10
I'd type in on the command line 'cpan MIME::Lite'.
00:00:17.48,00:00:20.04
And what I noticed is that it gives me a message here,
00:00:20.41,00:00:23.27
telling me that there are certain modules that it would
00:00:23.27,00:00:24.03
like to install.
00:00:24.03,00:00:26.82
These are optional but highly recommended.
00:00:27.24,00:00:29.05
My problem with this is that...
00:00:30.30,00:00:30.87
There are two problems at least.
00:00:30.87,00:00:32.97
One of them is the 'File::Basename' here,
00:00:32.68,00:00:34.23
that's the standard module.
00:00:34.12,00:00:36.08
Why is it mentioned here?
00:00:36.16,00:00:37.76
The other problem is that,
00:00:38.12,00:00:42.26
actually most of these modules if not all of them are already in my system.
00:00:42.18,00:00:45.77
So I'm now confused by this.
00:00:45.92,00:00:47.90
It's going to upgrade them?
00:00:48.45,00:00:51.20
Which one exactly is going to be upgraded or
00:00:51.00,00:00:51.93
what's going to happen?
00:00:53.53,00:00:56.19
So I would rather not see this.
00:00:56.19,00:01:00.21
I would rather fix this,
00:01:00.36,00:01:03.01
Makefile.PL that generates this.
00:01:03.12,00:01:08.13
So, I quit the script. What can I do?
00:01:08.53,00:01:13.75
I could fetch the source code of this distribution from CPAN,
00:01:13.94,00:01:15.40
and try to fix it there.
00:01:15.73,00:01:16.18
But,
00:01:16.57,00:01:18.65
there might have been changes
00:01:18.89,00:01:19.85
to the modules
00:01:19.77,00:01:23.08
since it was uploaded last time to CPAN.
00:01:23.35,00:01:28.63
So, first of all, let's go to : metacpan.org.
00:01:28.66,00:01:32.25
And look for the module 'mime-lite'.
00:01:32.93,00:01:35.16
This is actually the distribution I'm looking for right now.
00:01:35.26,00:01:39.73
So here is the documentation of the module, and what can I see?
00:01:39.65,00:01:41.37
Normally here on the left hand side,
00:01:41.50,00:01:46.56
there should be a link to the version control system of the distribution.
00:01:46.47,00:01:48.46
In this module you don't see it.
00:01:48.56,00:01:50.71
If I just look for another one,
00:01:50.71,00:01:53.34
So, 'metacpan.org'.
00:01:53.05,00:01:55.99
If I just look for another module, for example padre.
00:01:56.00,00:02:00.16
Then you will see, here, clicking on here,
00:02:00.16,00:02:02.81
that here there is a clone repository link,
00:02:02.84,00:02:06.13
that leads to the subversion repository of padre.
00:02:06.56,00:02:08.29
We don't see it here.
00:02:08.79,00:02:13.65
So some people don't add it to their META.yml file, or not yet.
00:02:14.96,00:02:17.32
In some cases you can find the repository
00:02:17.36,00:02:20.57
in the documentation but if you click through this documentation
00:02:20.88,00:02:23.57
you won't find any of the references.
00:02:24.24,00:02:27.01
So, because I know Ricardo, and
00:02:27.02,00:02:30.49
I know that he is using github a lot.
00:02:30.38,00:02:34.95
So I assume that this module is also kept in the repository.
00:02:35.44,00:02:37.01
So I go to github.
00:02:37.91,00:02:43.03
Github, and there I type his nickname 'rjbs'.
00:02:43.29,00:02:46.44
And I look for the module.
00:02:46.80,00:02:50.42
So, I look for 'mime-lite'.
00:02:50.65,00:02:54.10
And here it is, 'mime-lite'.
00:02:54.28,00:02:55.02
I click on it.
00:02:55.02,00:03:00.37
This is the repository basically of the module,
00:03:00.80,00:03:02.46
I could fetch it from here.
00:03:02.52,00:03:04.64
for this are the links I could use,
00:03:04.75,00:03:08.39
but I'd rather use the more standard way here.
00:03:08.39,00:03:12.52
It is clicking on this fork button.
00:03:12.55,00:03:15.45
For this obviously I have to be registered and logged in to github,
00:03:15.98,00:03:18.12
but I have already done that.
00:03:18.19,00:03:20.57
So, I click on the fork button,
00:03:20.58,00:03:24.36
and it will generate me a fork of this project,
00:03:24.36,00:03:26.31
which is actually a good thing in here.
00:03:26.23,00:03:28.28
And once the fork has been done,
00:03:28.18,00:03:35.02
then it will give me the url for where I can fetch the repository.
00:03:34.94,00:03:39.24
So I go back to my console.
00:03:39.33,00:03:41.94
Here I'd rather go into this 'tmp' directory.
00:03:41.99,00:03:45.14
And type in 'git clone'
00:03:45.27,00:03:49.34
and the url that I fetched from the github repository.
00:03:49.31,00:03:54.43
Now this will bring over all the repository of that specific module.
00:03:54.32,00:03:56.10
And here it is already.
00:03:56.06,00:03:59.96
And now I can go into the module.
00:03:59.94,00:04:05.25
Into the directory and type 'perl Makefile.PL', the standard way to install.
00:04:05.28,00:04:07.92
And see that the thing is still here.
00:04:07.74,00:04:11.94
Although the File::Basename entry was taken already out.
00:04:11.90,00:04:12.99
So indeed,
00:04:13.25,00:04:16.63
things have changed since the latest release
00:04:16.34,00:04:19.10
that are not released to CPAN yet.
00:04:19.68,00:04:23.80
So let's go and take a look at the source code.
00:04:24.90,00:04:27.93
Here what I can see is that...
00:04:27.99,00:04:30.93
Well, first of all I don't see 'use strict' 'use warnings'.
00:04:30.80,00:04:35.09
And then here is a huge print statement printing out the names of the modules.
00:04:35.08,00:04:39.08
Then the prerequisites which are the requirements.
00:04:39.32,00:04:41.11
And then prompting
00:04:41.14,00:04:45.19
whether I want to add the additional prerequisites.
00:04:46.06,00:04:47.07
These ones.
00:04:47.63,00:04:49.46
So it is slightly confusing here.
00:04:49.45,00:04:51.80
And then here it says the actual names.
00:04:51.91,00:04:55.29
So let's do a slight refactoring here.
00:04:55.25,00:04:57.22
What I really want here is:
00:04:58.26,00:05:00.70
go over the names of the modules that are optional,
00:05:01.27,00:05:03.07
check that they are already installed,
00:05:02.96,00:05:06.08
check whether the installed is the right version number,
00:05:06.10,00:05:11.89
and display here only the ones that are either not installed yet,
00:05:12.06,00:05:14.35
or that I installed but they are old versions.
00:05:14.76,00:05:18.56
And if they are all installed with all the good versions,
00:05:18.93,00:05:21.97
then I don't want the whole thing to appear.
00:05:23.28,00:05:24.62
And I don't want the prompt.
00:05:24.97,00:05:29.04
So first of all let's move the definitions to the top.
00:05:29.13,00:05:34.02
I take this prerequisites and I put them in the top.
00:05:34.42,00:05:37.20
And then let's unite the two lists.
00:05:36.96,00:05:41.22
So there is the list of the modules and here is the same list again.
00:05:41.44,00:05:43.59
Let's create all lists.
00:05:43.69,00:05:50.95
So here I put in '%optional'.
00:05:50.72,00:05:52.66
And take the four values,
00:05:54.70,00:05:57.75
and create the hash here.
00:05:58.13,00:05:59.79
So,
00:06:03.94,00:06:06.60
that still should be exactly the same.
00:06:06.79,00:06:09.24
Now, as I'm going to compare version numbers.
00:06:09.39,00:06:12.82
I think I'd rather have here 0s instead of 'undef'.
00:06:12.85,00:06:15.30
Which, basically these just mean
00:06:15.20,00:06:18.37
that we don't get a rich version
00:06:18.19,00:06:22.85
of the module installed, we just want to have that module we installed.
00:06:23.05,00:06:26.16
So now I still have the same code.
00:06:26.16,00:06:32.42
If I save the file and put the editor in the background.
00:06:32.80,00:06:38.64
Now I can run the script just checking out that everything is still the same.
00:06:39.42,00:06:42.29
So it looks so far ok, I haven't broken anything.
00:06:43.55,00:06:49.07
Now , instead of these four values, let's put in here a String.
00:06:49.47,00:06:52.56
So here I just put in some kind of a string,
00:06:52.54,00:06:54.31
that I would like to print.
00:06:54.73,00:06:57.82
And let's fill that String here
00:06:57.64,00:06:58.86
So I have
00:06:59.46,00:07:02.65
the 'str', which should be empty
00:07:02.65,00:07:03.42
at the beginning
00:07:04.03,00:07:11.47
and then I go over 'foreach my', sorry that should be a dollar sign '$name'.
00:07:12.06,00:07:14.54
All the keys of the optional hash.
00:07:19.23,00:07:21.23
So I go over all that entries,
00:07:21.84,00:07:25.36
and I can just add them to the String.
00:07:25.36,00:07:33.18
So I just add '\t $name \n' to the String.
00:07:32.99,00:07:35.78
So basically this is still the same right?
00:07:35.63,00:07:37.20
Now I can remove this,
00:07:37.88,00:07:44.96
and I can run the code and it is still the same. So far so good.
00:07:47.40,00:07:51.44
Now comes the issue that I would like to check whether I include
00:07:51.44,00:07:55.73
this '%str' only the ones that
00:07:55.72,00:07:58.68
are not installed or that are to old.
00:08:00.38,00:08:01.65
So what do I do?
00:08:01.69,00:08:05.07
First of all I need to use the module.
00:08:08.37,00:08:11.30
Sorry that should be '$name'. So use the name.
00:08:11.61,00:08:14.52
And I put the whole thing into an eval String.
00:08:16.82,00:08:20.57
So it would catch an exception if the module is not installed.
00:08:21.07,00:08:25.78
Then I check whether the module is installed or not.
00:08:26.02,00:08:33.18
Now if it is not installed, then I need to put in the String right?
00:08:33.01,00:08:40.08
So let's see, if there was no error message, then everything is ok.
00:08:40.25,00:08:41.82
If there was an error message,
00:08:41.86,00:08:45.04
then keep it like this, put it in the String.
00:08:45.04,00:08:46.05
Ok?
00:08:45.78,00:08:48.54
But if there was no error message,
00:08:48.82,00:08:50.55
then we still need to check
00:08:50.40,00:08:52.55
whether the version number is correct.
00:08:52.79,00:08:58.01
So we say 'elsif' and then we put the '$name->VERSION',
00:08:58.01,00:09:00.68
this is the actual version number of the installed module.
00:09:01.10,00:09:03.92
And we would like to check whether it is smaller than
00:09:03.92,00:09:07.20
the version
00:09:08.01,00:09:11.38
declared here '$optional{$name}'.
00:09:13.11,00:09:17.58
If it's smaller, then we would like to add the same thing.
00:09:17.45,00:09:19.11
So let's copy here.
00:09:21.10,00:09:23.38
Otherwise we just don't edit.
00:09:23.21,00:09:25.38
So let's see what happens now.
00:09:26.04,00:09:27.98
If I run the script,
00:09:28.27,00:09:33.09
then it tells me the beginning of the report and the end of it
00:09:33.09,00:09:34.74
and there are no modules listed.
00:09:34.84,00:09:37.94
So probably it means that either I made a bug here
00:09:37.93,00:09:40.78
or actually all the modules are installed.
00:09:40.86,00:09:42.56
Let's check that out.
00:09:45.11,00:09:47.51
So, what happens if I just change the name?
00:09:49.96,00:09:53.17
Indeed, so if the module name is something that's not installed
00:09:53.05,00:09:54.66
then it would show up here.
00:09:54.10,00:09:57.57
That's good so I didn't break that part.
00:09:57.72,00:10:03.58
And what happens if I put here 10 instead of version 1.
00:10:05.66,00:10:07.76
Then it catches that module,
00:10:07.76,00:10:11.17
so apparently that module is still not at version 10.
00:10:11.58,00:10:18.58
So both parts are working and they are both including the message.
00:10:18.94,00:10:24.71
Now what I would like here is to display this whole thing the print and the prompt
00:10:24.63,00:10:27.01
only if there were any values there.
00:10:27.14,00:10:29.03
And that's not too bad because...
00:10:29.43,00:10:31.94
not too difficult because
00:10:31.94,00:10:34.23
'$str' String is going to be empty
00:10:34.29,00:10:36.41
if we haven't added anything to it.
00:10:36.26,00:10:43.70
So we can actually check whether 'if($str)' and only if the '$str' is there,
00:10:43.97,00:10:47.02
only then
00:10:47.02,00:10:48.14
print the prompt.
00:10:48.78,00:10:50.36
Only then print out anything,
00:10:50.33,00:10:52.99
and only then prompt.
00:10:53.10,00:10:55.85
So if I now try this out again,
00:10:56.35,00:10:58.15
then it won't ask me anything
00:10:58.15,00:11:00.03
because all the modules are already installed.
00:11:00.90,00:11:04.65
And if I go back and do my little test,
00:11:05.31,00:11:08.11
and put here let's say this version number.
00:11:08.93,00:11:10.50
And run the script again
00:11:10.90,00:11:13.69
then it will tell me these modules need to be installed.
00:11:13.76,00:11:18.98
Not because this module is not there but because it is an older version.
00:11:19.22,00:11:22.94
A slight improvement would be to actually see.
00:11:23.21,00:11:26.75
So in this case when the version is incorrect
00:11:26.86,00:11:29.26
then I would like to see the actual version number.
00:11:29.84,00:11:33.40
So, actually here too,
00:11:33.38,00:11:37.83
I would like to see not only the name of the module but also the required version.
00:11:37.72,00:11:41.03
So I put in
00:11:42.48,00:11:47.44
the required version, here I do the same,
00:11:49.61,00:11:50.23
right?
00:11:50.15,00:11:54.51
So in both cases I print out the name of the module that has to be installed
00:11:54.83,00:11:56.48
and the version number to be installed.
00:11:56.88,00:12:01.00
But in this case I also would like to put in 'we found'
00:12:01.88,00:12:04.25
and here I would like to put in the version number
00:12:05.61,00:12:13.82
and that version number should be 'my $version' this '$optional{$name}',
00:12:14.16,00:12:14.96
right?
00:12:16.57,00:12:20.83
So if I run the script now it should tell me that
00:12:21.08,00:12:25.24
we want to have 'MIME::Types 10.28'
00:12:25.21,00:12:26.22
we found, oh!
00:12:26.11,00:12:27.06
That's not good!
00:12:29.78,00:12:35.34
We found the same version number so, not the optional name,
00:12:35.19,00:12:43.80
we need here the '$name->VERSION',
00:12:43.81,00:12:45.42
right? This is what we found.
00:12:45.83,00:12:47.60
So if I run this again.
00:12:48.15,00:12:49.76
Then indeed, it's better.
00:12:49.96,00:12:53.34
So we want, this one, but we found this version.
00:12:56.28,00:12:58.73
So that's it I think,
00:12:58.90,00:13:02.10
except that I have to put it back to the right version number.
00:13:02.18,00:13:07.76
And it now seems too that I've added all the necessary changes.
00:13:07.86,00:13:12.88
Now, a little bit more of what I want is the 'use strict'
00:13:12.86,00:13:15.85
and 'use warnings'
00:13:17.54,00:13:22.97
and let's try to run the script again and now it says '@EXES',
00:13:22.97,00:13:24.50
something that is an error.
00:13:25.12,00:13:29.50
So let's look where this error, this array can be found.
00:13:29.23,00:13:32.86
I use 'ack' to look for 'EXES'.
00:13:33.96,00:13:39.85
And the only place where it appears in this code is the 'Makefile.pl'
00:13:39.85,00:13:43.61
so probably is just some leftover from an earlier version.
00:13:44.56,00:13:48.98
And I think I can safely comment it out.
00:13:54.20,00:13:55.73
Well let's leave it for now.
00:13:55.91,00:13:57.34
Let's comment these out.
00:13:57.72,00:14:02.08
And let's leave it for Ricardo to make the actual changes.
00:14:02.91,00:14:04.86
So now if I try it again.
00:14:05.89,00:14:08.36
It looks like it's working.
00:14:09.99,00:14:10.76
Go back to the editor,
00:14:10.76,00:14:11.48
I quit the editor.
00:14:12.32,00:14:15.50
'git st' git status, so these are the files that have been changed.
00:14:15.32,00:14:17.40
Actually this was the file that has been changed,
00:14:17.18,00:14:20.65
this is a new file that was generated it is not really interesting.
00:14:20.70,00:14:25.62
So what I need now is 'git add Makefile.PL'.
00:14:25.72,00:14:30.63
That this file should be added back to the repository.
00:14:31.50,00:14:33.00
And now you see that's green.
00:14:33.06,00:14:44.89
And 'git ci -m “make optional modules optional”' ok.
00:14:46.04,00:14:49.44
And that's it so I checked in on my local git repository.
00:14:49.43,00:14:51.62
And then I can git push.
00:14:52.63,00:14:54.74
Push the repository out to github.
00:14:55.51,00:14:57.03
And once that's done.
00:14:56.95,00:14:59.63
Ok, so it's sent out to my git repository.
00:14:59.60,00:15:02.98
And I go back to see if I manage to do that.
00:15:03.10,00:15:04.70
I go back to my repository.
00:15:04.96,00:15:08.36
I can actually refresh the screen and then
00:15:08.33,00:15:13.50
we'll see that this is the last change in the repository.
00:15:13.60,00:15:15.91
And now I can send the pull request.
00:15:16.11,00:15:20.18
It's basically a message to Ricardo to integrate the changes.
00:15:21.47,00:15:32.30
'make optional module prompt optional'
00:15:33.31,00:15:35.65
and that's it so I send the pull request.
00:15:36.03,00:15:38.62
This will send a message to Ricardo and
00:15:38.72,00:15:40.96
hopefully he will integrate the modules soon.
00:15:40.86,00:15:46.61
I hope that you learned how to have this CPAN module here.
00:15:47.27,00:15:51.37
I'll try to do some other stuff with the same idea later on.
00:15:51.33,00:15:52.64
Thank you for listening.
00:15:52.89,00:15:53.53
Bye bye.
Jump to Line
Something went wrong with that request. Please try again.